简体   繁体   English

ValueError:解包的值太多

[英]ValueError:too many values to unpack

I'm a beginner and, when I try to transform date time to mins, I get the error:我是初学者,当我尝试将日期时间转换为分钟时,出现错误:

ValueError: too many values to unpack

Here's my code:这是我的代码:

def t2m(t):
    m,s,l = t.strip().split(":")
    return int(m)+int(s)/60+int(l)/6000

a= "0000-00-00 00:12:46:13"
d=a.strip('0000-00-00 00')

print(round(t2m(d)),1) 

You are getting the error because t.strip().split(":") returns 4 values and you are trying to put them into m,s,l .您收到错误是因为t.strip().split(":")返回 4 个值,并且您试图将它们放入m,s,l中。

You should replace your second line with:您应该将第二行替换为:

_,m,s,l = t.strip().split(":")

found out by myself.自己发现的。 should be like应该像

d=a.strip('0000-00-00 00:')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM