Question about using python as a scripting language

Delaney, Timothy (Tim) tdelaney at avaya.com
Sun Aug 6 23:13:39 EDT 2006


Steve Lianoglou wrote:

> One thing you could do is use the eval or compile methods. These
> functions let you run arbitray code passed into them as a string.
> 
> So, for instance, you can write:
> my_list = eval('[1,2,3,4]')

This is just asking for trouble.

my_list = eval('import shutil; shutil.rmtree('/')')

Terry's approach is much better. Another alternative is to create a
dictionary mapping an action name to a function. Basically the same as
Terry's solution, but the dictionary lookup is explicit (as opposed to
being hidden as method names).

Tim Delaney



More information about the Python-list mailing list