0

I have the code in python, as shown below:

import csv

fields = ['Output']
filename = 'data.csv'
MAX_DATA = 20


with open(filename, 'w', ) as csvfile:
    csvwriter = csv.writer(csvfile, lineterminator = '\n')
    csvwriter.writerow(fields)
    for i in range (0, MAX_DATA):
        action = '1000000000000000000000000000000000000000000000000000000000000001'
        print (action) # Just used to see terminal line by line output
        rows = [[action]]
        csvwriter.writerows(rows)

The above works great, and using print (action) I am able to see every action (the 64 bit string), being printed over and over again. Which is what I want/expect. I want to save the entire 64 bit string/int to csv, hence the csvwriter.

The problem I am running into is that when I open up the saved csv. My output in each row is 1E+63, written in each row, up to MAX_DATA. It's being changed into scientific form.

I need that output in the csv file the entire 64 bit 'action' value, whether that action value is a string or a int doesn't matter.

Chris Sears
  • 6,502
  • 5
  • 32
  • 35
  • How are you opening and reading the file? Are you converting to an int or float? – dawg Nov 09 '20 at 18:07
  • @dawg - opening and reading the file, in terms of viewing the output? I am going to where I saved the csv on my computer, and 'Open With' --> 'Excel' Edit: Actually, for the first time I tried opening data.csv using notepad, or a different program. The entire 64 bit int is shown. – Tyler Beauregard Nov 09 '20 at 18:11
  • 1
    For the part you have written here, the string will be written to your csv file. Take a look inside the file. The `1E+63` is being created by excel since 64 digits of accuracy is beyond its capability. – dawg Nov 09 '20 at 18:17
  • @dawg - so if I go to read from that same csv now, using csvwriter. And I read into python the first row from that csv, does it read `1E+63` or `that 64 bit string` – Tyler Beauregard Nov 09 '20 at 19:22
  • 1
    It will read the string. It remains a string until you convert it with `int` or `float` or if converted automatically by numpy or pandas – dawg Nov 09 '20 at 19:24

0 Answers0