ValueError:没有足够的值来解包(预期 4,得到 1) [英] ValueError: not enough values to unpack (expected 4, got 1)

查看:21
本文介绍了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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆