Python __all__用法
2017-05-16
留言
Python all用法
简单的说,Python all的作用就是约定from package import *的行为,比如有个模块:
foo.py定义如下:
|
|
此时,使用1from foo import *
导入所有对象时候,只能导入name和othername,无法导入其他的对象:123456789101112from foo import * osTraceback (most recent call last): File "<stdin>", line 1, in <module>NameError: name 'os' is not defined funTraceback (most recent call last): File "<stdin>", line 1, in <module>NameError: name 'fun' is not defined name,othername('foo', 'bar')