【发布时间】:2016-07-05 17:22:30
【问题描述】:
错误位于script, first, second, third = argv。我想了解我收到错误的原因以及如何解决它。
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)
【问题讨论】:
-
您只是在没有任何参数的情况下运行了脚本,为了让您的代码正常工作,您应该传递至少 3 个参数,例如
python script.py arg1 arg2 arg3 -
你遇到了什么错误?
-
我收到 ValueError: not enough values to unpack (expected 4, got 1),是因为我在 pycharm 中运行它而不是使用 cmd?
-
你需要告诉 pycharm 传入参数/参数,否则它只会执行不带任何参数的脚本。
-
我在运行“Learn Python 3 the Hard Way: A Very Simple Introduction to the Terrifyingly Beautiful World of Computers and Code”中的示例时遇到了同样的错误,当我发现你的问题时,我说,“我知道那个代码”。