A command in a String ?

Peter Moscatt pgmoscatt at optushome.com.au
Wed Apr 13 04:53:01 EDT 2005


</F>,

Thanks for the help on this.  Yea the 'exec' did the trick.
The second example just placed all the strings in one option button.

Pete



On Wed, 13 Apr 2005 10:34:20 +0200, Fredrik Lundh wrote:

> Peter Moscatt wrote:
> 
>>I have a rather odd question:
>>
>> Is there a way Python can execute a command within a string ?
>>
>> For example if I had something like:
>> _str = "fm=OptionMenu(root,xx,'string1','string2','string3')"
>>
>> And the execute _str.
> 
> exec _str
> 
>> The reason why I am trying to do this that as I am aware the OptionMenu
>> hasn't the ability insert options therefore the options would be inserted
>> by manipulating strings.
> 
> does this do what you want?
> 
>     strings = "string1", "string2", "string3"
>     fm = OptionMenu(root, xx, *strings)
> 
> </F>




More information about the Python-list mailing list