Stupid Python trick
Ben Wolfson
wolfson at midway.uchicago.edu
Tue Mar 13 03:14:31 EST 2001
I'm sure this can be put to creatively bad use.
Python 2.1b1 (#3, Mar 2 2001, 20:37:19)
[GCC 2.96 20000731 (Red Hat Linux 7.0)] on linux2
Type "copyright", "credits" or "license" for more information.
IDLE 0.6 -- press F1 for help
>>> class D:
def __init__(self, otherself, v):
self.val = v
try: otherself.val = v
except: pass
>>> import new
>>> d = D(None, 5)
>>> d.val
5
>>> m = new.instancemethod(D, d, D)
>>> m(6)
<__main__.D instance at 0x82df1dc>
>>> d.val
6
--
Barnabas T. Rumjuggler
Fried Something with Noodle: Very good for ugly, sad, lonely, sick
people with the blood and the grasses all over the floor...
-- Joe Frank, _A Call in the Night_
More information about the Python-list
mailing list