[Tutor] code blocks and output streams
op73418 at mail.telepac.pt
Mon Nov 10 07:16:59 EST 2003
On Sun, 9 Nov 2003 08:30:32 -0800 (PST), you wrote:
>I am trying to create a program that can have php-like
>embedding of Python in html files. First, I want to
>start out with a program that can take an html file
>with python code inside <py> tags (ie something like
><py>print 'hi'</py>). In trying to do this, I found
>two problems: executing complex code blocks (eg ones
>that must have some indentation) and creating a new
>output stream to direct things that are printed to.
>All I know about how to do this is that the exec
>keyword should be used to execute things and that I
>should change sys.stdout to change the output stream.
Let me add a bit on A. Gauld's answer and suggest that you visit the
Active State Python cookbook:
There is a recipe by A. Martelli (the martellibot) called YAPTU, Yet
Another Python Templating Utility. It may be all that you ever need as
far as templating goes. The code is also worth studying.
With my best regards,
More information about the Tutor