Quote:
|
Originally Posted by teknomage1
maybe redhead will respond since he actually uses python
|
Sorry tekno, I dont use python at a regular basis, I know of it and how it should be used, but I'm not currently involved in projects developed in the language. Thats why I havn't listed it as one of my known programming languages.
QUantumAnenome, In a case like the one you're looking for, you'd use the
Comma Separated Values module. Simply have your file comma seperated, or tab or whatever you like, and use the module to convert it back to your orriginal list.
Say you're using Excel as the delimiter you can store and retrieve your data in a matter like this:
Code:
import csv
a=[1,2,3,[4,5],6,[7,8,[9]],0]
writer = csv.writer(open("my_file", "wb"), csv.excel)
writer.writerows(a)
writer.close()
b=array()
reader = csv.reader(open("my_file", "rb"), csv.excel)
try:
for row in reader:
b.append(row)
except csv.Error, e:
sys.exit('file %s, line %d: %s' % (filename, reader.line_num, e))
reader.close()
print a
print b
Or perhaps you just want the easy and quick answer to this one... By using the
pickle serialization
Code:
import pickle
a = [1,2,3,[4,5,6],7,[8,[9]],0]
output = open('my_file', 'wb')
pickle.dump(a, output)
output.close()
input = open('my_file', 'rb')
b = pickle.load(input)
input.close()
print a
print b
a == b