Concrete classes -- stylistic question

John Hunter jdhunter at nitace.bsd.uchicago.edu
Thu Oct 10 18:43:16 CEST 2002


>>>>> "Andrew" == Andrew Koenig <ark at research.att.com> writes:

    Andrew> Am I reinventing the wheel here?  If so, where is the
    Andrew> original?

Does you approach have anything substantive over the following?

class Record:
   pass

foo = Record()
foo.x, foo.y = 3, 4

print foo.x
print foo.__dict__

boo = Record()
boo.r, boo.theta = 1, 0.5

print boo.x   #oops


Since your approach uses keyword args in Record, it doesn't seem like
you'll save any typing or clarity by using named keywords in the init
function rather than on the RHS of the tuple assignment.

Your __repr__ is a little prettier than printing __dict__, but no more
informative.  

JDH




More information about the Python-list mailing list