Skip to content

Instantly share code, notes, and snippets.

@clbarnes
Last active March 12, 2016 04:40
Show Gist options
  • Save clbarnes/ca899f1355f49090ab2e to your computer and use it in GitHub Desktop.
Save clbarnes/ca899f1355f49090ab2e to your computer and use it in GitHub Desktop.
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
1
2
3
[
1,
2,
3
]
“NUMPY F {'descr': '<i4', 'fortran_order': False, 'shape': (3,), }
sjbgojsnbgsdhngodshnfgopsnogisdgnsobgis
your_list = [1, 2, 3]
# using csv module
import csv
# write it
with open('list.csv', 'w') as f:
writer = csv.writer(f)
writer.writerows(your_list)
# read it
with open('list.csv') as f:
reader = csv.reader(f)
your_list2 = list(reader)
# using json
import json
# write it
with open('list.json', 'w') as f:
json.dump(your_list, f, indent=2) # the indent argument isn't necessary, just makes it easier for humans to read the file
# read it
with open('list.json') as f:
your_list2 = json.load(f)
# using numpy
import numpy as np
# write it
np.save('list.npy', your_list) # creates a file which can't be read by humans but numbers are full precision
# read it
your_list2 = np.load('list.npy')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment