csv - 字典不允许第三个值/变量
问题描述
当尝试运行一个简单的 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
解决方案
推荐阅读
- javascript - 未捕获的类型错误:对象原型可能只是一个对象或 null:未定义
- html - HTML/CSS 如何批量编辑网页上使用的 URL 以在本地缩短它们
- powershell - 使用 gMSA 和 Get-ADGroupMember 的 PowerShell 脚本
- elasticsearch - 用于字段映射的 Elasticsearch 索引和搜索时间分析器不起作用
- java - 静态内部类中的 Main 产生 ClassnotFoundException(尽管 $)
- javascript - 反应本机参考孩子
- python - apyori apriori 损坏的项目集输出
- excel - VBA - 从 Excel 文件中获取 URL 以供 IE 浏览
- firebase - 云函数以 500 响应,但 firebase 日志为空
- javascript - 以 php 形式显示 jQuery/JSON 值