Evil hack of the day

Neel Krishnaswami neelk at brick.cswv.com
Wed May 26 22:47:26 EDT 1999


In article <Pine.LNX.4.10.9905262141420.14143-100000 at NEW93126179.columbus.rr.com>,
Dan Eble  <eble at ticalc.org> wrote:
>On 26 May, Neel Krishnaswami wrote in comp.lang.python:
>
>NK> This leads to the evil version:
>NK> 
>NK> >>> def evil(n=0):
>NK> ... 	n = n + 1
>NK> ... 	globals()['evil'].func_defaults = (n,)
>NK> ... 	return n
>NK> ...
>
>
>That doesn't work for me.  Observe,
>
>
>Python 1.5.1 [...rest snipped...]
 ^^^^^^^^^^^^

There's the reason right there. Python 1.5.2 shows some rather
noticeable increases in dynamism over the previous version. Another
example: you can reassign the __bases__ attribute of a class in 1.5.2,
and you can't in 1.5.1.

It makes sense, in a perverse sort of way: since Python is already 
too dynamic to optimize efficiently, there's no real cost to going
whole-hog on making the language changeable at run-time.


Neel




More information about the Python-list mailing list