Simple question, how can i create a record?
Scott David Daniels
Scott.Daniels at Acm.Org
Sun Mar 2 19:48:14 EST 2003
EleKtR0 wrote:
> ... uses a module named "record" to import a class named "record"....
> How can i create records on Python?
I'll use "Record" for the name here, since class names are usually
capitalized where I come from.
You might simply do something like:
class Record: pass
then you can:
r = Record()
r.a = 23
...
To get fancier:
class Record:
def __init__(self, **keywordargs):
self.__dict__.update(keywordargs)
def __repr__(self):
return '%s(%s)' % (self.__class__.__name__,
','.join(['%s=%r' % keyval for keyval
in self.__dict__.items()]))
This works as the first one, prints nicely,
and allows initializations like:
r = Record(x=3, y=4.5, z=3+4j, name="O'Hara")
-Scott David Daniels
Scott.Daniels at Acm.Org
More information about the Python-list
mailing list