Is there a reason not to do this?
Ron Garret
rNOSPAMon at flownet.com
Fri Dec 1 12:48:20 EST 2006
In article <1164983226.620035.218790 at l12g2000cwl.googlegroups.com>,
"Carl Banks" <pavlovevidence at gmail.com> wrote:
> The principle behind this is pretty much "it was just a language design
> decision".
Yes, and I'm not taking issue with the decision, just pointing out that
the desire to do things differently is not necessarily perverse.
> P.S. If you want to be truly evil, you could use a class hook to get
> the modifying in-place behavior:
>
> def modify_in_place(name,bases,clsdict):
> cls = globals()[name]
> for attr,val in clsdict.iteritems():
> setattr(cls,attr,val)
> return cls
>
> # Replace second C2 class above with this
> class C2:
> __metaclass__ = modify_in_place
> def m1(self): h()
Doesn't work for me:
>>> c2
<__main__.C2 instance at 0x51e850>
>>> c2.m1()
G
>>> class C2:
... __metaclass__ = modify_in_place
... def m1(self): print 'Q'
...
>>> c2.m1()
G
>>> C2().m1()
Q
rg
More information about the Python-list
mailing list