Python不同??橄绿厥獗淞康氖褂?/p>
小妮浅浅
2021-09-06 10:01:213191浏览 · 0收藏 · 0评论
1、当模块(源文件)作为主程序运行,解释器将硬编码字符串赋值"__main__"给__name__变量。
# It's as if the interpreter inserts this at the top # of your module when run as the main program. __name__ = "__main__"
2、当??楸涣硪桓龅既胧?,导入语句中的名称分配给__name__变量。
假设某个其他??槭侵鞒绦虿⑶宜既肽哪?椤U庖馕蹲旁谥鞒绦蚧蛑鞒绦虻既氲钠渌?橹杏姓庋挠锞洌?/p>
# 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中的wxPython??槭鞘裁??
python??橐氲娜址绞?/a>
dir()函数在python模块的使用
python模块中判断全局变量的赋值
python模块如何传入参数