1.all列表的说明:
当模块中有__all__变量时,当使用from xxx import *时,只能导入这个列表中的元素。
2.具体的例子:
1.先创建一个模块my_mod,在列表__all__中分别写入第一次只写入test1,第二次写入test1、test2两个元素:
2. 在其他模块中用from xx import *语句调用my_mod结果如下:
第一次:
这是test1
Traceback (most recent call last):
File "D:/pycharm项目/数值类型.py", line 6, in <module>
test2()
NameError: name 'test2' is not defined
第二次:
这是test1
这是test2
两次运行的结果即可说明当模块中有__all__变量时,当使用from xxx import *时,只能导入这个列表中的元素。