掃二維碼與項目經(jīng)理溝通
我們在微信上24小時期待你的聲音
解答本文疑問/技術(shù)咨詢/運營咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流
1、當模塊(源文件)作為主程序運行,解釋器將硬編碼字符串賦值"__main__"給__name__變量。

創(chuàng)新互聯(lián)主營和平網(wǎng)站建設(shè)的網(wǎng)絡公司,主營網(wǎng)站建設(shè)方案,APP應用開發(fā),和平h5成都微信小程序搭建,和平網(wǎng)站營銷推廣歡迎和平等地區(qū)企業(yè)咨詢
# It's as if the interpreter inserts this at the top # of your module when run as the main program. __name__ = "__main__"
2、當模塊被另一個導入時,導入語句中的名稱分配給__name__變量。
假設(shè)某個其他模塊是主程序并且它導入您的模塊。這意味著在主程序或主程序?qū)氲钠渌K中有這樣的語句:
# Suppose this is in some other main program. import foo
解釋器將搜索您的foo.py文件(以及搜索其他一些變體),并且在執(zhí)行該模塊之前。
# 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學習指路:創(chuàng)新互聯(lián)python教程
本文教程操作環(huán)境:windows7系統(tǒng)、Python 3.9.1,DELL G3電腦。

我們在微信上24小時期待你的聲音
解答本文疑問/技術(shù)咨詢/運營咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流