python - 在 Valueerror 需要大于 1 的地方出现错误
问题描述
当在下面输入
from sys import argv
script, first, second, third = argv
print "The script is called:", script
print "Your first variable is:", first
print "Your second variable is:", second
print "Your third variable is:", third
我在下面收到此错误:
Traceback (most recent call last):
File "C:\python-files\ex13.py", line 3, in <module>
script, first, second, third = argv
ValueError: need more than 1 value to unpack
>>>
解决方案
您正在尝试访问命令行参数,这些参数仅在您以这种方式调用脚本时发送:
python script.py first_argument second_argument third_argument
每个参数都用空格隔开。你得到的错误是因为你试图访问参数但你没有传递它们。
尝试调用传递三个参数的脚本,它将得到修复
推荐阅读
- qualtrics - 如何有条件地将文本框添加到 Qualtrics 调查中的答案
- aem - AEM 6.x:如何临时/以编程方式禁用链接检查器?(尝试返回带有链接的 JSON 返回浏览器)
- vagrant - Laravel Homestead/Vagrant/Virtualbox 在 Windows 上运行缓慢
- php - 显示添加到网站目录的最新文件,同时排除 PHP 中的某些特定文件
- javascript - javaScript:如何检查参数是否与数组中的最后一个字符串匹配
- unity3d - Unity Tron 像轨迹粒子系统
- python - 根据另一个表中的列名在 MySQL 中创建表
- rest - 16 位 dBase 与 RESTful API 服务器的集成
- python - 本地使用 dask:对 Client() 还是对 Client()?
- web-scraping - 网页抓取:缺少某些页面 URL