Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python CSV writer truncates long numbers

Tags:

python

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.

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"]

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

like image 895
theasianpianist Avatar asked Mar 29 '26 17:03

theasianpianist


1 Answers

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

like image 120
theasianpianist Avatar answered Apr 01 '26 11:04

theasianpianist



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!