问题:
当使用writerows将数据写入CSV文件时,我当前在输入1000001时看到以下错误:ValueError: dict contains fields not in fieldnames: 1, 0, 0, 0, 0, 0, 1
字段名正确写入CSV(历史.csv)但不是结果。
说明
我正在尝试将搜索函数的输出写入一个单独的CSV文件,以便自己能够轻松地跟踪搜索数据。当我还在学习Python时,我觉得读然后写CSV将是一个好的开始。
详细信息
在Windows7计算机上使用Python3.2.3
功能
这个程序由3个函数组成(是的,我想练习写函数。如果这没有意义,请告诉我:search,csv_record,和{}。search函数来自原始的SO问题,csv_record包含编写代码,main只是将它们全部连接起来并请求用户输入。
样本数据1000001;Name here:1;1001;1;11;Item description here:1
1000002;Name here:2;1002;2;22;Item description here:2
1000003;Name here:3;1003;3;33;Item description here:3
1000004;Name here:4;1004;4;44;Item description here:4
1000005;Name here:5;1005;5;55;Item description here:5
1000006;Name here:6;1006;6;66;Item description here:6
1000007;Name here:7;1007;7;77;Item description here:7
1000008;Name here:8;1008;8;88;Item description here:8
1000009;Name here:9;1009;9;99;Item description here:9
编码
^{pr2}$
评论
我知道这不是一个免费的代码编写服务,但任何帮助将不胜感激。关于如何使用writerows,我有没有忘记什么?据我所知,阅读csv.py文件,它试图将我的用户输入加入结果,当它们将被写入CSV时。我的目标是只写结果,而不是我的用户输入(这将是另一件要学习的事情)。我删除了评论,但请问你是否需要解释。
资源