新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
創(chuàng)新互聯(lián)Python教程:Python不同模塊下特殊變量的使用
1、當(dāng)模塊(源文件)作為主程序運(yùn)行,解釋器將硬編碼字符串賦值"__main__"給__name__變量。

創(chuàng)新互聯(lián)主營(yíng)和平網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營(yíng)網(wǎng)站建設(shè)方案,APP應(yīng)用開發(fā),和平h5成都微信小程序搭建,和平網(wǎng)站營(yí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、當(dāng)模塊被另一個(gè)導(dǎo)入時(shí),導(dǎo)入語句中的名稱分配給__name__變量。
假設(shè)某個(gè)其他模塊是主程序并且它導(dǎo)入您的模塊。這意味著在主程序或主程序?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不同模塊下特殊變量的使用,希望對(duì)大家有所幫助。更多Python學(xué)習(xí)指路:創(chuàng)新互聯(lián)python教程
本文教程操作環(huán)境:windows7系統(tǒng)、Python 3.9.1,DELL G3電腦。
文章題目:創(chuàng)新互聯(lián)Python教程:Python不同模塊下特殊變量的使用
標(biāo)題鏈接:http://m.fisionsoft.com.cn/article/djsopji.html


咨詢
建站咨詢
