Alan G wrote:
> ...
> Take a look at the OOP topic in my tutor. It includes an examnple
> of how to save/load objects to text files.
Thanks Alan, Javier and Jonathon. The answers I got all showed me bits
of Python I haven't seen before! I'll have to take a while to digest the
others.
I left ano
class OOO (object):
def __init__ (i, **a): i.__dict__ = a
def __repr__ (i):
a = i.__dict__
return "%s (%s)" % (type (i).__name__, ", ".join (
"%s=%r" % (o, a [o]) for o in sorted (a.iterkeys ())
))
class OO (object):
def __init__ (i, *o, **a):
> I have a class that has half a dozen or so data fields. It needs to
> be
> able to save its data to a text file, in a format that's easy to
> edit
> with other tools (vi, perl, etc). And needs to be able to load
> itself
> back from disk.
Take a look at the OOP topic in my tutor. It includes
Darryl Luff wrote:
> [...] I created get/set methods for each field to avoid
> problems if I mis-type the dictionary keys.
An automated way to do that:
class M(type):
def create_properties(cls, obj, *prop_names, **prop_names_values):
for pname in prop_names:
setattr(cls,