美图齐众专注资阳网站设计 资阳网站制作 资阳网站建设
资阳网站建设公司服务热线:028-86922220

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

创新互联Python教程:Python不同模块下特殊变量的使用

1、当模块(源文件)作为主程序运行,解释器将硬编码字符串赋值"__main__"给__name__变量。

创新互联主营和平网站建设的网络公司,主营网站建设方案,APP应用开发,和平h5成都微信小程序搭建,和平网站营销推广欢迎和平等地区企业咨询

# It's as if the interpreter inserts this at the top
# of your module when run as the main program.
__name__ = "__main__"

2、当模块被另一个导入时,导入语句中的名称分配给__name__变量。

假设某个其他模块是主程序并且它导入您的模块。这意味着在主程序或主程序导入的其他模块中有这样的语句:

# Suppose this is in some other main program.
import foo

解释器将搜索您的foo.py文件(以及搜索其他一些变体),并且在执行该模块之前。

# It's as if the interpreter inserts this at the top
# of your module when it's imported from another module.
__name__ = "foo"

以上就是Python不同模块下特殊变量的使用,希望对大家有所帮助。更多Python学习指路:创新互联python教程

本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。


本文名称:创新互联Python教程:Python不同模块下特殊变量的使用
新闻来源:http://www.zsjierui.cn/article/djsopji.html

其他资讯