Is it possible to “dynamically” create local variables in Python? [duplicate]
This question already has an answer here: Dynamically set local variable [duplicate] 7 answers Is it possible to create a local variables with Python code, given only the variable's name (a string), so that subsequent calls to "'xxx' in locals()" will return True? Here's a visual : >>> 'iWantAVariableWithThisName' in locals() False >>> junkVar = 'iWantAVariableWithThisName' >>> (...some magical code...) >>> 'iWantAVariableWithThisName' in locals() True For what purpose I require this trickery is another topic entirely... Thanks for the help. If you really want to do this, you could use exec :