[英]Why is my Python script not running via command line?
謝謝!
def hello(a,b):
print "hello and that's your sum:"
sum=a+b
print sum
import sys
if __name__ == "__main__":
hello(sys.argv[2])
它對我不起作用,我感謝您的幫助!!! 謝謝!
在沒有看到錯誤消息的情況下,很難確切地說出問題出在哪里,但是有幾件事跳出來:
可能更多,但再次需要錯誤輸出。
這是您可能想要的:
import sys
def hello(a,b):
print "hello and that's your sum:"
sum=a+b
print sum
if __name__ == "__main__":
hello(int(sys.argv[1]), int(sys.argv[2]))
sys
,而不是在函數末尾導入。 hello
發送兩個參數 ,其中一個是不夠的。 這將導致:
import sys
def hello(a, b):
sum = a + b
print "hello and that's your sum:", sum
if __name__ == "__main__":
hello(float(sys.argv[1]), float(sys.argv[2]))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.