【发布时间】:2019-06-13 08:23:53
【问题描述】:
我有一本字典作为输出。价值观很混乱。它们采用字符串/列表形式。我需要从中删除方括号和引号,以便可以在 CSV 文件中正确打印它们。我怎样才能做到这一点?
这是字典:
{'table': [['abc']], 'from': [['abc']], 'where_expr': ['c', '=', 'book']}
我希望它变成这样: {'table': abc, 'from': abc, 'where_expr': c, =,book} 和我的 csv 文件作为
表|从| where_expr
abc | abc |c = 书
(我只是使用 | 显示不同的列)
dict1=delr.asDict()
with open('delf.csv', 'w') as f: x
w = csv.DictWriter(f, dict1.keys())
w.writeheader()
w.writerow(dict1)
【问题讨论】:
-
相当肯定的欺骗问题
-
for k in dict1.keys(): dict1[k] = dict1[k][0][0]
标签: python csv dictionary