[Numpy-discussion] exec: bad practice?

Sebastien Binet seb.binet at gmail.com
Tue Sep 15 10:59:37 EDT 2009


On Tuesday 15 September 2009 16:30:43 Rick White wrote:
> You're not supposed to write to the locals() dictionary.  Sometimes
> it works, but sometimes it doesn't.  From the Python library docs:
> 
> locals()
> 	Update and return a dictionary representing the current local symbol
> table.
> 	Note: The contents of this dictionary should not be modified;
> changes may not affect the values of local variables used by the
> interpreter.
ah! I am glad I tried to show off my python shaky python skills :)

> I think the only way to create a variable with a program-specified
> name in the local namespace is to use exec (but I'd be happy to be
> corrected).
looks like so.
I am sure there is a good reason for being able to programmatically modify the 
globals() dict content but not the locals() one...

cheers,
sebastien.
-- 
#########################################
# Dr. Sebastien Binet
# Laboratoire de l'Accelerateur Lineaire
# Universite Paris-Sud XI
# Batiment 200
# 91898 Orsay
#########################################



More information about the NumPy-Discussion mailing list