老师,我也碰上了这个问题。具体设置是这样的:
folder: Chapter8
folder: t
file: __init__.py:
code: __all__ = ['c1']
file: c1.py:
code:
__all__ = ['a', 'c']
a = "this is a in module t.c1"
b = "this is b in module t.c1"
c = "this is c in module t.c1"
file: c2.py:
code:
f = "this is f in module t.c2"
file: c3.py:
code:
from t import *
print(c1.a)
print(c1.b)
final result:
"this is a in module t.c1"
"this is b in module t.c1"
问题:
使用 from t import * 时,c1.py中的__all__定义的['a', 'c']并没有起作用.
所以b可以能被打印出来。
如果换成from t.c1 import *时,c1.py中的__all__定义的['a', 'c']起作用
所以b不能被打印出来。
是不是__all__起作用的范围有什么规则?