Variable names on the fly?

Gerhard Häring gerhard.haering at gmx.de
Thu Nov 14 21:09:04 EST 2002


Gonçalo Rodrigues wrote:
> Gerhard Häring <gerhard.haering at gmx.de>:
>>for i in range(3):
>>    locals()["list%i" % i] = []
> 
> Although I'm sure you are aware of it, here is for general information:
> 
> From the docs on locals:
> "Return a dictionary representing the current local symbol table.
> Warning: The contents of this dictionary should not be modified; changes
> may not affect the values of local variables used by the interpreter."

No, I wasn't aware of this. Thanks for pointing it out. OTOH I don't
use such ugly constructs in real life :)

-- Gerhard



More information about the Python-list mailing list