首页 > 解决方案 > 字典不允许第三个值/变量

问题描述

当尝试运行一个简单的 csv 行来拆分然后添加到字典时,这就是我剩下的。如果它只是 a 和 b 并且我删除了与 c 相关的所有内容,那么它的效果很好,但现在它只是失败了。

现在所有的数据库都是

first1, last1, 1000
first2, last2, 1000
first3, last3, 1000
db = open('logindata.txt', 'r')
u = []
p = []
m = []
for dnary in db:
    a, b, c = dnary.split(", ",2)
    b = b.strip()
    c = c.strip()
    u.append(a)
    p.append(b)
    m.append(c)
data = dict(zip(u, p, m))
print(a, b, c)

这就是它给我留下的任何想法?

Traceback (most recent call last):
  File "I:\Project\other builable thingy.py", line 12, in <module>
    data = dict(zip(u, p, m))
ValueError: dictionary update sequence element #0 has length 3; 2 is required

Process finished with exit code 1

标签: csvdictionarysplitappendstrip

解决方案


推荐阅读