Skip to content
Advertisement

Convert a string to preexisting variable names

How do I convert a string to the variable name in Python?

For example, if the program contains a object named self.post that contains a variable named, I want to do something like:

JavaScript

Advertisement

Answer

As referenced in Stack Overflow question Inplace substitution from ConfigParser, you’re looking for eval():

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement