Update to PEP 227 (static scoping)
Fredrik Lundh
fredrik at pythonware.com
Thu Feb 22 02:51:18 EST 2001
I wrote:
> Note that in real life, "free" means "global or builtin". For example,
> this common Tkinter pattern will no longer compile:
>
> import sys
> def makeui():
> from Tkinter import *
> def callback():
> print "bye"
> sys.exit(1)
> Button(command=callback).pack()
>
> # gives an error on line two (the first def statement)
also note that one easy way to fix this is to use the
default argument hack (!):
import sys
def makeui():
from Tkinter import *
def callback(sys=sys):
print "bye"
sys.exit(1) # this works!?
Button(command=callback).pack()
I'm glad I didn't sign up to do that Python book ;-)
Cheers /F
More information about the Python-list
mailing list