Python新手,用于使用MATLAB。使用输入参数从命令行运行Python函数
我的功能convert.py是:
def convert(a,b)
factor = 2194.2
return (a-b)*factor
如何从输入参数“a”和“B”的命令行运行呢? 我试过了:
python convert.py 32 46
但是出错了。
我曾尝试在网上找到答案,找到相关的东西,但不是问题的答案:
- Python: Run function from the command line(堆栈溢出)
- Command Line Arguments In Python(堆栈溢出)
- http://www.cyberciti.biz/faq/python-command-line-arguments-argv-example/
- http://www.saltycrane.com/blog/2007/12/how-to-pass-command-line-arguments-to/
另外,我在哪里可以找到答案mysel f以便我可以保存此论坛以获取更多不重要的问题?
你有什么错误? – kennytm
用'sys.argv [1]'和'sys.argv [2]'代替'a'和'b',同时结帐'argparse' –
检查[this document](http://stackoverflow.com/documentation/) python/1382/parsing-command-line-arguments#t = 201608171014404401577)out。 – Selcuk