[Tutor] How can I convert a variable name to a string?

Emile van Sebille emile at fenx.com
Fri Sep 21 22:24:52 CEST 2012


On 9/21/2012 2:11 AM Dae James said...
> How can I convert a variable name to a string ?
> For example:
> testVariable = 1000;
> How can I get the string "testVariable" ?

If what you're asking is 'how do I get the value associated with the the 
string "testVariable"?' then yuo can use something like:

locals()["testVariable"]

Emile





More information about the Tutor mailing list