作者demonxxx (demon)
看板Python
标题[问题] 如何透过另一个py档来run?
时间Wed Aug 1 15:31:56 2012
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
1F:推 darkgerm:execfile('test.py') 08/01 16:44
2F:→ demonxxx:单独使用这行是可以的,但是我如果加在def里就没反应? 08/01 16:57
3F:→ demonxxx:因为我另一个py档有写def x(): 然後在x() 执行 08/01 16:58
4F:推 weslychu:import test 08/03 00:13
5F:→ weslychu:test.test(xxx.xxx) 08/03 00:14
6F:→ demonxxx:TypeError: getattr():attribute name must be string 08/03 10:01