Another approach is to add a parser.
Below is a very quick and dirty adaptation of Moinmoin's Hello World parser.
import StringIO
import sys
class Parser():
def __init__(self, raw, request, **kw):
self.raw = raw
self.request = request
self.kw=kw
def format(self, formatter):
# Execute the code
code_out = StringIO.StringIO()
sys.stdout = code_out
exec self.raw
sys.stdout = sys.__stdout__
out_lines = code_out.getvalue().split("\n")
# Print the output
for out_line in out_lines:
self.request.write(formatter.rawHTML(out_line+"<br>"))
If it is saved for example as path/to/MoinMoin/parser/interpret_python.py
, then you can enter into a page
{{{#!interpret_python
for j in [1,3,5]:
print(j)
}}}
and it will produce the text
1
3
5
when viewing the page. Can be made safe(r) by confining the execution to a sandbox.