local variable referenced before assignment

Alf P. Steinbach alfps at start.no
Mon Apr 5 00:35:25 CEST 2010


* Stephen Hansen:
> 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.

Thanks, I didn't see that. I thought it was a global.


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


Cheers,

- Alf



More information about the Python-list mailing list