这是一个创建于 2680 天前的主题,其中的信息可能已经有所发展或是发生改变。
>随后,我们以不传递参数的形式使用 dir 函数。在默认情况下,它将返回当前模块的属性列表。要注意到被导入进来的模块所能生成的列表也会是这一列表的一部分。
#给出当前模块的属性名称
dir()
['__builtins__', '__doc__', '__name__', '__package__']
这个“返回当名模块”的到底是哪个模块? 模块名是什么?
比如下面这个例子:
import sys
#给出 sys 模块中的属性名称
dir(sys)
['__displayhook__', '__doc__', 'argv', 'builtin_module_names', 'version', 'version_info']
#only few entries shown here
这个例子中很明显导入的是 sys 模块。
求指教。
Byte Of Python 73P
|
|
1
ruoyu0088 2017-06-03 21:17:09 +08:00 1
Python 中每个文件就是一个模块,dir()得到当前文件中的所有全局名字。当前模块名就是当前文件的名字。
|