ValueError:没有足够的值来解包(预期为 4,得到 1) [英] ValueError: not enough values to unpack (expected 4, got 1)
问题描述
from sys import argv
script, first, second, third = argv
print("The script is called: ", script)
print("The first variable is: ", first)
print("The second variable is: ", second)
print("The third variable is: ", third)
错误位于 script, first, second,third = argv
.我想了解为什么我会收到错误以及如何修复它.谢谢!
The error is at script, first, second, third = argv
. I would like to understand why I am getting the error and how to fix it. Thank you!
推荐答案
argv
变量包含命令行参数.在您的代码中,您期望有 4 个参数,但只有 1 个(第一个参数始终为脚本名称).您可以在 pycharm
中配置参数.转到 Run
-> Edit Configurations
.然后创建一个新的python配置.在那里你可以指定 Script parameters
字段.或者您可以从命令行运行脚本,如 dnit13 所述.
argv
variable contains command line arguments. In your code you expected 4 arguments, but got only 1 (first argument always script name). You could configure arguments in pycharm
. Go to Run
-> Edit Configurations
. Then create a new python configuration. And there you could specify Script parameters
field. Or you could run your script from command line as mentioned by dnit13.
这篇关于ValueError:没有足够的值来解包(预期为 4,得到 1)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!