How do I accomplish variable variables in Python?
Here is an elaborative manual entry, for instance: Variable variables
I have heard this is a bad idea in general though, and it is a security hole in Python. Is that true?
How do I accomplish variable variables in Python?
Here is an elaborative manual entry, for instance: Variable variables
I have heard this is a bad idea in general though, and it is a security hole in Python. Is that true?
Use the built-in
getattr
function to get an attribute on an object by name. Modify the name as needed.Use
globals()
You can actually assign variables to global scope dynamically, for instance, if you want 10 variables that can be accessed on a global scope
i_1
,i_2
...i_10
:This will assign 'a' to all of these 10 variables, of course you can change the value dynamically as well. All of these variables can be accessed now like other globally declared variable: