在 Python 中使用命令行参数:了解 sys.argv [英] Using command line arguments in Python: Understanding sys.argv
本文介绍了在 Python 中使用命令行参数:了解 sys.argv的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前正在学习艰难的学习 Python".我认为这个例子可能已经过时,所以我想在这里获得反馈.
I'm currently going through Learn Python The Hard Way. I think this example might be out dated so I wanted to get feedback here on it.
我使用的是 Python 3.1
I'm using Python 3.1
from sys import argv
script, first, second, third = argv
print("the script is called:", (script))
print("your first variable is:", (first))
print("your second variable is:", (second))
print("your third variable is:", (third))
我收到此错误:
Traceback (most recent call last):
File "/path/ch13.py", line 3, in <module>
script, first, second, third, bacon = argv
ValueError: need more than 1 value to unpack
知道出了什么问题吗?
推荐答案
您忘记将参数传递给脚本,例如foo.py bar baz quux
.
You forgot to pass arguments to the script, e.g. foo.py bar baz quux
.
这篇关于在 Python 中使用命令行参数:了解 sys.argv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文