ValueError: not enough values to unpack (expected 4, got 1)(ValueError:没有足够的值来解包(预期 4,得到 1))
问题描述
错误出现在 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.
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
中配置参数.转到 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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:ValueError:没有足够的值来解包(预期 4,得到 1)


基础教程推荐
- kivy 应用程序中的一个简单网页作为小部件 2022-01-01
- Kivy 使用 opencv.调整图像大小 2022-01-01
- 比较两个文本文件以找出差异并将它们输出到新的文本文件 2022-01-01
- 对多索引数据帧的列进行排序 2022-01-01
- matplotlib 设置 yaxis 标签大小 2022-01-01
- 在 Django Admin 中使用内联 OneToOneField 2022-01-01
- 在 Python 中将货币解析为数字 2022-01-01
- Python,确定字符串是否应转换为 Int 或 Float 2022-01-01
- 究竟什么是“容器"?在蟒蛇?(以及所有的 python 容器类型是什么?) 2022-01-01
- Python 中是否有任何支持将长字符串转储为块文字或折叠块的 yaml 库? 2022-01-01