Re: [問題] __name__的使用時機?

看板Python作者 (Are you ready,too?)時間15年前 (2009/06/24 14:15), 編輯推噓2(203)
留言5則, 3人參與, 最新討論串2/3 (看更多)

06/24 13:54,
06/24 13:54
l大給的網頁講得有點模糊 Knowing this, you can design a test suite for your module within the module itself by putting it in this if statement. 這句話讓我不太懂放了這個statement對於我的模組做出什麼樣的testing This makes it easier to develop and debug new modules before integrating them into a larger program. 結論看得懂 但不知道為什麼會有這個結論 還是不太懂if __name__=='__main__'的用意 不知道版友能不能幫不才的小弟解釋一下? 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 118.167.24.92 ※ 編輯: RUReady2 來自: 118.167.24.92 (06/24 14:15)

06/24 14:27, , 1F
就是說,單獨執行時你的程式名稱是 __main__, 反之是原名
06/24 14:27, 1F

06/24 14:28, , 2F
你可以寫成單獨執行時跑 test suite, 反之是一般模組
06/24 14:28, 2F

06/24 14:34, , 3F
g大講的第二句看不懂 可以請g大舉個例嗎?
06/24 14:34, 3F

06/24 14:35, , 4F
精華區有喔
06/24 14:35, 4F

06/24 14:38, , 5F
精華區第三段後兩行看不懂...
06/24 14:38, 5F
文章代碼(AID): #1AGSHhjK (Python)
文章代碼(AID): #1AGSHhjK (Python)