Malcolm Greene wrote: > New to Python and looking for a template library that allows Python > expressions embedded in strings to be evaluated in place. In other words > something more powerful than the basic "%(variable)s" or "$variable" > (Template) capabilities. > > I know that some of the web frameworks support this type of template > capability but I don't need a web framework, just a library that > supports embedded expression evaluation. ... > Any suggestions appreciated.
EmPy may work: http://www.alcyone.com/software/empy/ Your template would look something like: myOutput = """\ The total cost is @invoice.total. This order will be shipped to @invoice.contact at the following address: @invoice.address This order was generated at @time.ctime() """ This could be instrumented with something as simple as: >>> import em, time >>> myOutput = """\ ... ... The total cost is @invoice.total. ... ... This order will be shipped to @invoice.contact at the following ... address: ... ... @invoice.address ... ... This order was generated at @time.ctime() ... """ >>> >>> class Invoice: pass ... >>> invoice = Invoice() >>> invoice.total = "$123.45" >>> invoice.contact = "Jack McCoy" >>> invoice.address = "1 Police Plaza\nNew York City, NY" >>> print em.expand(myOutput, globals()) The total cost is $123.45. This order will be shipped to Jack McCoy at the following address: 1 Police Plaza New York City, NY This order was generated at Thu Mar 6 18:41:58 2008 -- Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/ San Jose, CA, USA && 37 18 N 121 57 W && AIM, Y!M erikmaxfrancis There's a reason why we / Keep chasing morning -- Sandra St. Victor -- http://mail.python.org/mailman/listinfo/python-list