Generic constructors and duplication of internal Python logic
Peter Otten
__peter__ at web.de
Fri Apr 23 04:51:29 EDT 2004
Peter Otten wrote:
> But will I stop trying to come up with something better? no way. Here's my
> next try, and I'm likely to present something completely different again
> if you don't like it - not sure if that's a promise or a threat :-)
A threat.
def setLocals(d, selfName="self"):
self = d.pop(selfName)
for n, v in d.iteritems():
setattr(self, n, v)
class Demo(object):
def __init__(self, foo, bar, baz=2, bang=3):
setLocals(locals())
Peter
More information about the Python-list
mailing list