[Tutor] how to read and write to a file

ken brockman krush1954 at yahoo.com
Wed Jan 25 13:19:15 CET 2012


I would like to write to and read from a file from python. I wanted to use the file to save input to the program in a list. I have been looking around and there seems to be several ways to go about it. I tried pickling, but am having an issue with it. What would be the correct way to accomplish this? I have tried several ways, but to no avail. I get no error msg. but the list isn't retaining the info. Is pickling even the best way to do it.

file1 = open("ArtyKlikes.p", "ab")  # likesList
file2 = open("ArtyDislikes.p", "ab")  # dislikes

pickle.dump(likesList, file1)
pickle.dump(dislikeList, file2)

file1.close()
file2.close()

Any help would be greatly appreciated.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120125/1fbc48d5/attachment.html>


More information about the Tutor mailing list