看了 6.1.1. Executing modules as scripts 裡面有寫
"the code in the module will be executed, just as if you imported it, but with the __name__ set to "__main__". That means that by adding this code at the end of your module:"
試著作一次
- C:\Python33\say.py
def say(words): print(words) if __name__ == '__main__': import sys say(sys.argv[1]) print(__name__,sys.argv[0])
- Output
C:\Python33>python.exe say.py hello hello __main__ say.py
這樣就可以了, 很簡單..
沒有留言:
張貼留言