这是我的 python hello.py
脚本:
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])
问题是不能从windows命令行提示符运行,我用的是这个命令:
C:\Python27>hello 1 1
不幸的是,它没有用,有人可以帮忙吗?
最佳答案
-
import sys
退出 hello 函数。 - 参数应转换为 int。
- 包含
'
的字符串字面量应该转义或应该被"
包围. - 您是否使用
python hello.py <some-number> <some-number>
调用了该程序?在命令行中?
import sys
def hello(a,b):
print "hello and that's your sum:", a + b
if __name__ == "__main__":
a = int(sys.argv[1])
b = int(sys.argv[2])
hello(a, b)
关于python - 如何在 Windows 命令行中使用参数运行 Python 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17544307/