Python CSV编写器会截断长整数 [英] Python CSV writer truncates long numbers

查看:72
本文介绍了Python CSV编写器会截断长整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在从事一个项目,该项目需要产生一个包含大量信息作为最终输出的CSV文件.我目前将所有数据存储在一个非常大的列表中,然后使用CSV包将其写入CSV文件.我的问题是,数据字段之一包含一个非常长的数字,该数字存储为字符串,但是第15个数字之后的任何数字都被替换为0.直到将其写入CSV文件的方式.

I'm currently working on a project which needs to produce a CSV file containing a bunch of info as the final output. I currently store all the data in a very large list, which I then write to a CSV file with the CSV package. My issue is that one of the data fields contains a very long number stored as a string, but any digit after the 15th digit is replaced with a 0. I've stepped through with a debugger and the number is represented correctly in the list all the way up to the point where it gets written to the CSV file.

这是我的CSV编写器方法:

Here's my CSV writer method:

b = open('phoneTest4.csv', 'wb')
a = csv.writer(b, dialect="excel")
a.writerows(List)
b.close()

列表实际上是一堆子列表,每个子列表代表一个项目以及与该项目相关联的元数据.子列表的格式如下:

List is actually a bunch of sublists, with each sublist representing one item and metadata associated with said item. The sublists are formatted as such:

["20120402180644691","Some Text", "Another number"]

在最终的CSV文件中,第一个数字存储为"20120402180644600",而不是实际数字.我以前从未使用过CSV模块,并且Python文档似乎并未说明任何有关字符串/整数长度限制的信息

In the final CSV file, the first number is stored as "20120402180644600" instead of the actual number. I've never used the CSV module before, and the Python documentation doesn't appear to say anything about string/integer length limits

推荐答案

原来,Excel在显示大数字方面存在局限性,而CSV编写器模块没有问题.

Turns out Excel has a limitation on displaying large numbers, nothing wrong with the CSV writer module.

这篇关于Python CSV编写器会截断长整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆