Python Abuse 8.11.2003

2003-11-08

Python's not private enough!

>>> def foo():
...     thisIsPrivate = [0]
...     def bump():
...         thisIsPrivate[0] += 1
...     def read():
...         return thisIsPrivate[0]
...     return bump, read
... 
>>> bumper, reader = foo()
>>> 
>>> bumper(); bumper(); bumper(); print reader()
3

Now, for even more abuse... It's possible to access and change the list held in the closure "thisIsPrivate". But I'm not going to tell you how!

posted at 00:39:12    #    comment []    trackback []
November
MoTuWeThFrSaSu
      1 2
3 4 5 6 7 8 9
10111213141516
17181920212223
24252627282930
Oct Dec

Nothing quite like the smell of abusive python code in the morning.

XML-Image Letterimage

© 2003, Donovan Preston