global variables

Steven Bethard steven.bethard at gmail.com
Tue Oct 2 19:28:16 EDT 2007


TheFlyingDutchman wrote:
> Does anyone know how the variables label and scale are recognized
> without a global statement or parameter, in the function resize() in
> this code:
[snip]
> def resize(ev=None):
>       label.config(font='Helvetica -%d bold' % \
>           scale.get())

You're just calling a method on the "label" object. Python looks in the 
function local namespace and doesn't see a "label" object, so it steps 
up to the global namespace. There is a "label" object in the global 
namespace so it uses that one.

STeVe



More information about the Python-list mailing list