Embedding python code into text document question.

Erik Max Francis max at alcyone.com
Thu Jan 10 23:06:49 CET 2008


Thomas Troeger wrote:

> I've written a program that parses a string or file for embedded python 
> commands, executes them and fills in the returned value. The input might 
> look like this:
> 
> process id: $$return os.getpid()$$
> current date: $$return time.ctime()$$
> superuser: $$
> if os.geteuid():
>     return "Yes"
> else:
>     return "No"$$
> 
> I've tried several solutions using eval, execfile or compile, but none 
> of those would solve my problem. Does anyone have a solution that works? 
> Any suggestions? Any help will be appreciated :)

What you're looking for is a templating system for Python.  There are 
already many with varying degrees of complexity and emphasis, including 
one I've put together, EmPy:

	http://www.alcyone.com/software/empy/

For more, google around for Python templating.

-- 
Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
  San Jose, CA, USA && 37 18 N 121 57 W && AIM, Y!M erikmaxfrancis
   If the sun comes up / And you're not home / I'll be strong
    -- India Arie



More information about the Python-list mailing list