Python __all__系统变量

Posted 庖丁解牛

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python __all__系统变量相关的知识,希望对你有一定的参考价值。

#__all__系统变量的使用
‘‘‘
__all__可以赋值一个字符串列表,列表中的元素表示外界调用该py文件可以使用的函数或者类
如果使用了__all__系统变量,并且调用该py文件使用的是from xxx import *这种方式
那么将无法调用没有写在__all__变量中的方法


注意:通过 "import send"方式或者"from send import xxx"方式,那么仍然可以调用相应的方法


‘‘‘
__all__ = ["Msg"]

class Msg(object):
        def send(self):
                print("send message .")



def test():
        print("i am test from send.py")


if "__main__" == __name__:
        test()
else:
        print("send.py 正在被调用.")

 

以上是关于Python __all__系统变量的主要内容,如果未能解决你的问题,请参考以下文章

Python中from module import * 导包方式下的__all__变量

python中模块的__all__属性

阅读python的base64.py源代码

今天要学习的技术点,Python 筛选数字,模块导入,特殊变量__all__ 实战博客

你不了解的Python冷知识__all__的作用/模块导入

day 4 __all__ 包 __init__.py