empy 1.3 -- Embed Python in template text as markup

Neil Hodgson nhodgson at bigpond.net.au
Sun Aug 25 19:00:09 EDT 2002


Erik Max Francis:


> One could certainly perform this kind of thing in empy, but I'm not sure
> of how much use it would be.  I'm not quite seeing how to integrate such
> functionality into a tool unless it was specifically designed for it.
> (empy is the arbitrary embedding of Python code in template text, not
> for this particular type of macro operation in particular.)

   First design some syntax like @!expr!...! which is replaced by
@!expr!result_of_expr! by empy. Then my example becomes

# @!"\nLEXOBJS= \\\n" + "\\ \n".join(["\t$(DIR_O)\\" + y for y in f]) +
"\n#"!!

   Upon first expansion with f = ["LexAda", "LexAVE", "LexCPP"] this becomes

# @!"\nLEXOBJS= \\\n" + " \\\n".join(["\t$(DIR_O)\\" + y for y in f]) +
"\n#"!
LEXOBJS= \
 $(DIR_O)\LexAda \
 $(DIR_O)\LexAVE \
 $(DIR_O)\LexCPP
#!

   Further expansions yield the same result with the same f or equivalent
results with updated f.

   The syntax given above is too likely to run into problems as a simple '!'
is too likely to occur in the expression or expansion, so possibly some more
'@' based tokens could be used like @!expr@~...@|

   Neil






More information about the Python-list mailing list