Pickle vs XML for file I/O

crystalattice crystalattice at gmail.com
Mon Jul 31 20:24:09 EDT 2006


I'm creating an RPG for experience and practice.  I've finished a
character creation module and I'm trying to figure out how to get the
file I/O to work.

I've read through the python newsgroup and it appears that shelve
probably isn't the best option for various reasons.  This lead me to
try messing w/ pickle, but I can't figure out how to use it with
classes.  I've found many examples of using pickle w/ non-OOP code but
nothing that shows how to use it w/ classes, subclasses, etc.  I've
read the documentation but it doesn't explain it well enough for me.

Then I started thinking perhaps I'm going about it wrong.  My current
thought is to save an instance of each character so all the info (name,
skills, hit points, etc.) is stored in one place.  But looking at
OpenRPG made me think that perhaps using XML to store the information
would be better.  Each character could have a separate XML file, though
I don't know how it would work if many NPC's are required.

I guess my question is, what are the benifits of getting pickle to work
w/ my classes vs. converting all the character data into XML and just
writing that to a file?  Since most of the data would need to be
modified often, e.g. hit points, is one storage format better than the
other?  Can you even modify data if it's been pickled w/o having to
unpickle it, change the data, then repickle it?




More information about the Python-list mailing list