Formatted string to object

Tim Chase python.list at tim.thechases.com
Mon Jun 19 12:23:16 EDT 2006


> Can you use strings or %s strings like in the above or
> 
> aaa = 'string'
> aaa.%s() % 'upper'
> 
> Somehow?

Looks like you want to play with the eval() function.

 >>> aaa = 'hello'
 >>> result = eval("aaa.%s()" % 'upper')
 >>> result
'HELLO'

Works for your second example.  May work on your first example too.

-tkc






More information about the Python-list mailing list