Thanks for that clarification.  I'm sure there's a reason for this asymmetry 
(must declare globals to write them, but not to read them), but it's really 
weird.

On Jul 1, 2011, at 6:12 PM, Geoffrey Spear wrote:

> 
> 
> On Jun 29, 1:40 pm, Joshua Smith <joshuaesm...@charter.net> wrote:
>> I have this code in one of my apps:
>> 
>> townCache = {}
>> def getTown(id):
>>  if not id in townCache:
>>    townCache[id] = TownModel.get_by_id(id)
>>  return townCache[id]
>> 
>> Is this thread safe?  I think it is, because the worst that happens is the 
>> assignment happens redundantly with the same data.
>> 
>> Random other question: Why don't I have to say "global townCache" at the top 
>> of that function?
> 
> You can't *assign* to a global variable in another scope without the
> global keyword; however, townCache is the global name here, not
> townCache[id].
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Google App Engine" group.
> To post to this group, send email to google-appengine@googlegroups.com.
> To unsubscribe from this group, send email to 
> google-appengine+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/google-appengine?hl=en.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.

Reply via email to