[問題] 如何透過另一個py檔來run?

看板Python作者 (demon)時間13年前 (2012/08/01 15:31), 編輯推噓2(204)
留言6則, 3人參與, 最新討論串1/2 (看更多)
test.py class test(xxx.xxx): def xxx(self): self.xxx.xxx() if __name__ == "__main__": xxx.main() 我單獨run test.py是可以的。 我想寫一個py檔去呼叫test.py來run,我該如何做? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.32.231.88

08/01 16:44, , 1F
execfile('test.py')
08/01 16:44, 1F

08/01 16:57, , 2F
單獨使用這行是可以的,但是我如果加在def裡就沒反應?
08/01 16:57, 2F

08/01 16:58, , 3F
因為我另一個py檔有寫def x(): 然後在x() 執行
08/01 16:58, 3F

08/03 00:13, , 4F
import test
08/03 00:13, 4F

08/03 00:14, , 5F
test.test(xxx.xxx)
08/03 00:14, 5F

08/03 10:01, , 6F
TypeError: getattr():attribute name must be string
08/03 10:01, 6F
文章代碼(AID): #1G6DjkIs (Python)
文章代碼(AID): #1G6DjkIs (Python)