Pickle vs XML for file I/O
Marc 'BlackJack' Rintsch
bj_666 at gmx.net
Wed Aug 2 13:50:36 EDT 2006
In <1154539264.728714.247000 at h48g2000cwc.googlegroups.com>, crystalattice
wrote:
> One other question though (hope it doesn't sound silly/stupid). Your
> suggestion to "pickle a party" using a list has me thinking: can a
> list store class instances?
Yes of course you can store class instances in lists.
> For example, if I wanted to store a party of characters, rather than
> pickling each person separately could I put each character instance in
> a list then pickle the list? Like this:
>
> char1 = Character()
> char2 = Character()
> char3 = Character()
> party = [char1, char2, char3]
> file = open("partyfile.dat", "w")
> pickle.dump(party, file)
Yes that would work.
Ciao,
Marc 'BlackJack' Rintsch
More information about the Python-list
mailing list