Re: "pickle" vs. f.write()

2005-02-05 Thread Martin Miller
Marc 'BlackJack' Rintsch wrote: > ... > > I write __repr__() methods similar but I think a bit more readable: > > def __repr__(self): > return "%s(%r, %r, %r, %r)" % (self.__class__.__name__, self.name, > self.age, self.friends, self.comment) > > And it'

Re: "pickle" vs. f.write()

2005-02-02 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Martin Miller wrote: > I've found extending this property to your own classes often fairly easy > to implement (and useful). For example: > >> class person: >> def __init__(self, name="", age=0, friends=None, comment=""): >> if friends is None: >> f

Re: "pickle" vs. f.write()

2005-02-01 Thread Martin Miller
On 1/26/05 at 1:48 pm, Terry Reedy wrote: > For basic builtin objects, repr(ob) generally produces a string that when > eval()ed will recreate the object. IE > eval(repr(ob) == ob # sometimes I've found extending this property to your own classes often fairly easy to implement (and useful). For

Re: "pickle" vs. f.write()

2005-02-01 Thread mmiller at tx3 dot com
On 1/26/05 at 1:48 pm, Terry Reedy wrote: > For basic builtin objects, repr(ob) generally produces a string that when > eval()ed will recreate the object. IE > eval(repr(ob) == ob # sometimes I've found extending this property to your own classes often fairly easy to implement (and useful). For

Re: "pickle" vs. f.write()

2005-01-26 Thread Terry Reedy
For basic builtin objects, repr(ob) generally produces a string that when eval()ed will recreate the object. IE eval(repr(ob) == ob # sometimes For writing and reading class instances, pickle is the way to go. Terry J. Reedy -- http://mail.python.org/mailman/listinfo/python-list

Re: "pickle" vs. f.write()

2005-01-26 Thread Johan Kohler
Thanks... works like a charm :-) On Wed, 26 Jan 2005 12:55:38 +0100, Peter Maas <[EMAIL PROTECTED]> wrote: Johan Kohler schrieb: class person: name ="" age = 0 friends=[] comment="" me = person() Otherwise, what is the best "Python" way to write and read this data structure

Re: "pickle" vs. f.write()

2005-01-26 Thread Peter Maas
Johan Kohler schrieb: class person: name ="" age = 0 friends=[] comment="" me = person() Otherwise, what is the best "Python" way to write and read this data structure? import pickle class person: name ="" age = 0 friends=[] comment="" me = person() # store

"pickle" vs. f.write()

2005-01-26 Thread Johan Kohler
Hi, I have a class with attributes that are string, integer and list. eg. class person: name ="" age = 0 friends=[] comment="" me = person() I want to save a whole bunch of instances to a file, a classic "records" file I/O. To write the file, I can do f.write