Implementation of the global statement

Greg Ewing see_reply_address at something.invalid
Thu Nov 28 17:52:02 EST 2002


Bengt Richter wrote:

> This kind of stuff raises questions in my mind as to what
> will be guaranteed to work forever and what may be quasi-experimental,
> or depend on things that really shouldn't be locked in to become
> a millstone of backwards-compatibility to inhibit Guido's freedom.


I'd say that things like func_code and func_globals
are pretty much on the internals side and likely to
change.

For instance, there is a likelihood that access to
global variables will be optimised one day so that
it works more like local variable access does now.
If that happens, functions will probably become
much more tightly associated with the namespace
they were defined in, and this sort of transplanting
trick may no longer be possible.

>  >>> def foo(x): print x
>  ...
>  >>> bar = foo.__get__('Hi via foo')
>  >>> bar()
>  Hi via foo
>  >>> bar
>  <bound method ?.foo of 'Hi via foo'>

> how locked in is this feature? 


I don't know, my brain just exploded while I was trying
to figure out what was going on there...

> What should be the advice for/against using it


I think the advice should be: don't even THINK
about using it!

Who-says-you-can't-write-obfuscated-code-in-Python-ly,

-- 
Greg Ewing, Computer Science Dept,
University of Canterbury,	
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg




More information about the Python-list mailing list