vars(selenium.webdriver)返回的属性少于dir(selenium.webdriver)

时间:2019-03-19 08:03:54

标签: python python-3.x

我正在学习硒,发现非常有趣的东西。

In [5]: chrome.get("http://www.python.org")
In [6]: chrome.title
Out[6]: 'Welcome to Python.org'

测试dirvars的内置功能

In [24]: len(vars(chrome))
Out[24]: 10

In [25]: len(dir(chrome))
Out[25]: 118

dir返回的属性比vars多得多,并且有一些交集

In [29]: set(vars(chrome)).intersection(set(dir(chrome)))
Out[29]: 
{'_file_detector',
 '_is_remote',
 '_mobile',
 '_switch_to',
 'capabilities',
 'command_executor',
 'error_handler',
 'service',
 'session_id',
 'w3c'}

以前,如果在类中定义特殊的vars,我认为dir__dict__的功能强大。

为什么vars返回的属性比dir少,尤其是其中没有其他属性

In [30]: set(vars(chrome)) - set(dir(chrome))
Out[30]: set()

0 个答案:

没有答案