Hi, I'm trying to use a .txt file to store data (in lists) for python, but I've got no idea how to go about this. Would that even be a good way to store lists?
Text doc lists [solved]
Collapse
This topic is closed.
X
X
-
Originally posted by BellumHi, I'm trying to use a .txt file to store data (in lists) for python, but I've got no idea how to go about this. Would that even be a good way to store lists?
Code:filename = r"C:\myFile" # (r)aw strings work for windows dir names outputFile = file(fileName, "w") # open/create a file object in (w)rite mode outputFile.writelines(stringList) outputFile.close()
-
Following is what I have been doing to save dictionaries. It should work for lists also.Code:import pickle def export_data(file_name, dd): try: f = open(file_name, "w") pickle.Pickler(f).dump(dd) f.close() return dd except: Warning("Default file export error.") return 0 export_data('your_file_name.txt', your_list)
Comment
Comment