local variable referenced before assignment

Stephen Hansen apt.shansen at gmail.invalid
Sun Apr 4 18:32:36 EDT 2010


On 2010-04-04 15:22:48 -0700, Alf P. Steinbach said:

> * johngilbrough:
>> I cannot make sense of what's happening here ...  I'm getting the
>> following error:
> (1)
> At least in Py3 you can declare the variable as 'global', like this:
> 
>     global lastModifiedTime
> 
> within the function.

Actually, what you're looking for in py3 is the "nonlocal" keyword, 
which addresses this precise situation. Using "global" would mark the 
variable as *global* -- top-level module namespace.

nonlocal (within "handler") would make the assignment apply to the 
enclosing scope lastModifiedTime, instead.

-- 
--S

... p.s: change the ".invalid" to ".com" in email address to reply privately.




More information about the Python-list mailing list