Python commands in an interpreted script

Steve Holden sholden at holdenweb.com
Thu Jan 24 09:43:58 EST 2002


"Heiko Wolf" <heiko.wolf at dlr.de> wrote in message
news:d013da35.0201240218.2a199df at posting.google.com...
> Hi,
>
> I've got a python program here that reads out from script like
>
> key_word1
> key_word2
>
> and interprets the keywords, e.g. if keyword1 is read funtion1 is
> started. Now I want to use Python funtionality in that script, e.g. a
> loop like
>
> for i in range(10):
>   keyword1
>
> if I want keyword1 to be interpreted 10 times.
> Is there a way that Python executes commands, but just interprets
> certain strings?
>
There are many "templating" utilities in Python: Yaptu from Alex Martelli,
and Cheetah sprint to mind as two of the simpler packages not too-closely
focused on any one application.

Use a templating utility to perform the replacements you need, then run the
code with "exec".

Ane bear in mind that you have to guard against malicious users in such
schemes, to make sure the code you are running does not perform some
subversive act such as deleting files, sending mail, etc.

regards
 Steve
--
Consulting, training, speaking: http://www.holdenweb.com/
Python Web Programming: http://pydish.holdenweb.com/pwp/








More information about the Python-list mailing list