将unicode数据写入csv的问题

时间:2018-06-04 20:33:39

标签: python python-2.7 csv unicode

我无法理解如何将此数据类型写入csv文件。我正在使用Python 2.7中的请求,这将以<type 'unicode'>的形式返回。这只是数据片段:

"sizeOfApplication":0,"totalFailedFolders":0,"totalFailedFiles":0,"isVisible":true,"localizedStatus":"Running","isAged":false,"totalNumOfFiles":0,"jobId":955329,"sizeOfMediaOnDisk":0,"status":"Running","lastUpdateTime":1528140228,"percentSavings":0,"localizedOperationName":"Auxiliary Copy","statusColor":"greenspan","backupLevel":0,"jobElapsedTime":1732834,"jobStartTime":1526389208,"currentPhaseName":"Auxi"sizeOfApplication":179325630,"backupSetName":"Databases","totalFailedFolders":0,"totalFailedFiles":0,"isVisible":true,"localizedStatus":"Running","isAged":false,"totalNumOfFiles":54,"jobId":971203,"sizeOfMediaOnDisk":27870043,"status":"Running","lastUpdateTime":1527914335,"percentSavings":84.4584,"localizedOperationName":"Backup","statusColor":"greenspan","backupLevel":1,"jobElapsedTime":241877,"jobStartTime":1527897616,"currentPhaseName":"Backup","jobType":"Backup","backupLevelName":"Full"

当我尝试将其设置为literal_eval时,我得到一个值错误:格式错误的字符串,当我查看它时,我在想它,因为输出中有十进制数据,并且ast不支持十进制。< / p>

cvData = ast.literal_eval(str(r.text))

我尝试过以下方法也不起作用:

with open('mycsvfile.csv', 'wb') as f:
    w = csv.DictWriter(f, r.text.keys())
    w.writeheader()
    w = csv.DictWriter(writerow(r.text))

显然,这是椅子和键盘之间的问题,我提前道歉,因为我的python技能非常缺乏。

有没有办法让这个输出正确或删除/转换小数(假设这是问题)?

0 个答案:

没有答案