automatically naming a global variable

Remco Gerlich scarblac at pino.selwerd.nl
Tue May 22 15:00:50 EDT 2001


Chad Everett <chat at linuxsupreme.homeip.net> wrote in comp.lang.python: 
> If I have a string variable defined, how can I create a global
> variable with the same name as the string?
> 
> For example:
> 
> >>> x = "variable_name'
> 
> Now I want to be able to use x to create a global variable whose
> name is 'variable_name'
 
Can someone explain to me why this question comes up so often?

(The answer is something like - this is a bad idea, use a dictionary).

What use is a global variable that you don't know the name of, so you have
to use <insert favorite hack here> once more to get to its value?

-- 
Remco Gerlich



More information about the Python-list mailing list