Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python ValueError:没有足够的值来解包(预期值为4,实际值为1)_Python_Pycharm - Fatal编程技术网

Python ValueError:没有足够的值来解包(预期值为4,实际值为1)

Python ValueError:没有足够的值来解包(预期值为4,实际值为1),python,pycharm,Python,Pycharm,错误出现在script,first、second、third=argv。我想了解我为什么会出现错误以及如何修复它。谢谢大家! 从shell运行它,如下所示: 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: ",

错误出现在
script,first、second、third=argv
。我想了解我为什么会出现错误以及如何修复它。谢谢大家!

从shell运行它,如下所示:

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)

argv
变量包含命令行参数。在代码中,您需要4个参数,但只得到1个(第一个参数总是脚本名)。您可以在
pycharm
中配置参数。转到
运行
->
编辑配置
。然后创建一个新的python配置。您可以在那里指定
脚本参数
字段。或者您可以从命令行运行脚本,如dnit13所述。

您可以这样运行:python script.py first、second、third

我想您正在运行以下命令:

python script.py arg1 arg2 arg3
python script.py
您正在编写一个程序,该程序需要4个输入,并且只提供一个输入。这就是您收到错误的原因。您可以使用以下命令:

python script.py arg1 arg2 arg3
python script.py

您只是在没有任何参数的情况下运行了脚本,要使代码正常工作,您应该传递至少3个参数,如
python script.py arg1 arg2 arg3
您得到了什么错误?我得到了ValueError:没有足够的值来解包(预期为4,得到了1),这是因为我在pycharm中运行它而不是使用cmd吗?您需要告诉pycharm传入参数/参数,否则它只会在没有任何参数的情况下执行脚本。我在运行当我发现你的问题时,我说:“我知道那段代码”。当你在运行命令时没有在命令上输入足够的参数时,就会发生这种情况。