0

So yeah, I created a Card class and a Hand class and I've been trying to figure out for a while now how to store a Hand object as a text file onto the disk then be able to read it back into a new hand object but I'm still just totally confused? Looked at Pickle and Json too to figure out how to do it but was was overwhelmed and still couldn't figure things out. Can anyone help? I want to do this by adding code to my main method in the Lab 9 module:

The Three Modules: https://gist.github.com/kyotosomo

EDIT: By text file I don't mean a pickle, I already know how to do that. I mean a .txt file.

Kyotosomo
  • 11
  • 2
  • I know you said you have looked at `Pickle`, but [this answer seems quite simple to implement.](http://stackoverflow.com/a/2345201/833070) Have you tried it and if so, what issues did you have? – Draken Jun 07 '16 at 08:20
  • Well my issue is I need to save it as a .txt file, not a pickle file. One of the things I tried was this but then I got a Type error: [LINE 1] json.dump(startingHand, open("startingHand.txt", 'w')) [LINE 2] newHand = json.load(open("text.txt")) [LINE 3] print(newHand) – Kyotosomo Jun 07 '16 at 08:25
  • Does it have to be a text file? That could cause issues later on for reading it back in due to lack of specific data structure, or a data structure that you have to maintain yourself. [What about storing it as an XML file instead?](http://stackoverflow.com/questions/1019895/serialize-python-dictionary-to-xml). I'm just curious as to why it has to be a text file. – Draken Jun 07 '16 at 09:10
  • Because this is a homework assignment with guidelines. Our first extra credit option was using pickle; I did that. Our second option (worth even more) is to save it as a human readable file and read back from that file into a new object. It's like 2:30AM, the assignment is due at 8:00AM, and I've dead tired, frustrated as I've been trying to figure this out for hours, and still have gotten zero help on it. I just want to know how to save my object as a readable file regardless of whether the logic makes sense. This point could make or break me getting an A versus an A- in the class... – Kyotosomo Jun 07 '16 at 09:21
  • XML is definitely a human readable file, [and is possible like in this answer](http://stackoverflow.com/a/2101938/833070). Though that will do the work for you, not sure if you need to do it yourself. If you do, you have to have a go and come back when you have a more concrete and precise problem I'm afraid. – Draken Jun 07 '16 at 09:29

0 Answers0