Looking for very light weight template library (not framework)
Jeff McNeil
jeff at jmcneil.net
Thu Mar 6 22:41:20 EST 2008
Cheetah (http://www.cheetahtemplate.org/) and Mako
(http://www.makotemplates.org/) come to mind. Isn't there some long
running joke about new Python programmers creating their own template
language or something, too? =)
I know you said you don't want a web framework, but I've always been a
fan of Django templates in that they don't really allow you to do too
much inside the template itself. That seems to help keep a lot of
ex-PHP/JSP/ASP programmers I know honest.
On 3/6/08, Erik Max Francis <max at alcyone.com> wrote:
> 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 && max at alcyone.com && 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
>
More information about the Python-list
mailing list