Executing a string as python code

Paul Winkler slinkp23 at yahoo.com
Wed Oct 24 08:37:32 CEST 2001


On Wed, 24 Oct 2001 13:45:09 +1000, Richard Jones
<richard at bizarsoftware.com.au> wrote:
>On Wednesday 24 October 2001 13:30, Stephen Boulet wrote:
>> Can someone tell me how to execute an arbitrary string as python code?
>>
>> I'm trying to make a bunch of lists named list00, list01, ..., to list99 (I
>> don't want to make a single list of lists, since list00 is actually already
>> a list of lists), and I thought doing this as a string would be the easiest
>> way.
>>
>> I guess a dictionary with string keys and list values would be another way
>> (maybe a better way).
>
>Pretty much any time you're considering "execute an arbitrary string as 
>python code", you're doing things the (hard|insecure) way.
>
>Investigate using a dictionary.

Yep. But if you insist on the arbitrary string thing:
exec()

-- Paul Winkler



More information about the Python-list mailing list