Create multiple variables (with a loop?)

Chris Rebert clp2 at rebertia.com
Sat Jun 6 03:57:52 CEST 2009


On Fri, Jun 5, 2009 at 6:44 PM, Gökhan SEVER<gokhansever at gmail.com> wrote:
> You could use locals() for dynamic variable names creation.

Not really. Quoting
http://docs.python.org/library/functions.html#locals (emphasis mine):

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**.

It does happen to work it certain cases, but it should not be relied upon.

Cheers,
Chris
-- 
http://blog.rebertia.com



More information about the Python-list mailing list