Python: ValueError: too many values to unpack

eg1:

>>>a,b=(1,2,3)

Traceback (most recent call last):

  File "<stdin>",line 1,in <module>

ValueError: too many values to unpack (expected 2)

错误原因: 一个tuple值赋给一个tuple变量时,变量个数不够造成的

可以改成 a,b,c=(1,2,3)或者其他变量即可

eg2:

>>>import collections

>>>s=[(‘y‘,1),(‘b‘,1),(‘r‘),(‘y‘,2)]

>>>d=collections.defaultdict(list)

>>>for k,v in s:

...  d[k].append(v)

...

Traceback (most recent call last):

  File "<stdin>",line 1,in <module>

ValueError: too many values to unpack (expected 2)

错误原因:    s=[(‘y‘,1),(‘b‘,1),(‘r‘),(‘y‘,2)] 这句里面的(‘r‘) 变量个数不够了

可以改成 s=[(‘y‘,1),(‘b‘,1),(‘r‘,1),(‘y‘,2)]或者其他值即可

原文地址:https://www.cnblogs.com/baxianhua/p/8275627.html

时间: 2024-11-12 22:39:32

Python: ValueError: too many values to unpack的相关文章

Celery ValueError: not enough values to unpack (expected 3, got 0)的解决方案

最近因项目需要,在使用任务队列Celery的时候,出现如题错误,最终在github上里找到解决办法,记录一下. 运行环境环境:win10 + python3 + redis 2.10.6 + celery 4.2.1 win10上运行celery4.x会出现这个问题,开启任务队列一切正常(显示ready提示),一旦接受任务,就报ValueError: not enough values to unpack (expected 3, got 0)错误,解决办法如下: 1.先安装一个扩展 event

celery 启用worker ValueError: not enough values to unpack

[2018-01-12 19:08:15,545: INFO/MainProcess] Received task: tasks.add[5d387722-5389-441b-9b01-a619b93b4702][2018-01-12 19:08:15,550: ERROR/MainProcess] Task handler raised error: ValueError('not enough values to unpack (expected 3, got 0)',)Traceback

ValueError: too many values to unpack

Error msg: 执行: python manage,py makemigrations 报错:Value: too many values to unpack 问题: django第一次数据库迁移之后, apps中的model位置改变了, 导致之前生成的迁移文件检测不到原来的位置 解决: 删除所有的迁移文件重新迁移, 或者将之前的迁移文件的路径修改正确 原文地址:https://www.cnblogs.com/hpcm/p/9998037.html

python调用cv2.findContours时报错:ValueError: not enough values to unpack (expected 3, got 2)

OpenCV旧版,返回三个参数: im2, contours, hierarchy = cv2.findContours(mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) 要想返回三个参数: 把OpenCV 降级成3.4.3.18 就可以了,在终端输入pip install opencv-python==3.4.3.18 OpenCV 新版调用,返回两个参数: contours, hierarchy = cv2.findContours(mask, cv

python3 split( ) not enough values to unpack(expceted 2, got 1)

在运行一个小脚本时,脚本从一文本文件读取数据,事实上这个文件只有一行'count:2',并取到这个2,将其转成数字.但运行,总是报错. 代码如下: 1 with open('count.txt', 'r') as file: 2 if not file.readline(): 3 pass 4 else: 5 name, count = file.readline().split(':') 6 count = int(count) code 错误信息如下: '''Traceback (most

libsvm easy.py ValueError: need more than 0 values to unpack windows下终极解决

现象是: python easy.py train test 输出: Scaling training data...WARNING: original #nonzeros 100389 new #nonzeros 9983948Use -l 0 if many original feature values are zerosCross validation...Traceback (most recent call last): File "easy.py", line 61, i

Python学习——struct模块的pack unpack示例

import struct pack.unpack.pack_into.unpack_from # ref: http://blog.csdn.net/JGood/archive/2009/06/22/4290158.aspx import struct #pack - unpack print print '===== pack - unpack =====' str = struct.pack("ii", 20, 400) print 'str:', str print 'len(

Python ValueError: IO operation on closed file

ValueError IO operation on closed file表示处理了已经被关闭的数据,在python 中 with语句的上下文会帮助处理,也就是说,当python的处理代码不对齐的时候会出现这种情况.例子如下: header那一行,突出,也就是文件在之前一行关闭了.就会报错ValueError: IO operation on closed file.如图: 解决方法就是把header后移.如图: 运行结果如图所示: 问题成功解决!

rror: too many values to unpack

方法返回值 原文地址:https://www.cnblogs.com/UUUz/p/10279219.html