当前位置:首页 > Python教程 > python技巧

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 正在被调用.")

 

原文:https://www.cnblogs.com/zhanggaofeng/p/9696035.html


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!

相关教程推荐

其他课程推荐