Perl Template Toolkit: Now in spicy new Python flavor

eefacm at gmail.com eefacm at gmail.com
Wed Jan 16 15:01:43 EST 2008


On Jan 15, 1:45 pm, George Sakkis <george.sak... at gmail.com> wrote:
> > eef... at gmail.com wrote:
> > > I'd like to inform the Python community that the powerful and popular
> > > Template Toolkit system, previously available only in its original
> > > Perl implementation, is now also available in a beta Python
> > > implementation:
>
> > >http://tt2.org/python/index.html
>
> > > I created this port both as a fun programming project, and for use in
> > > environments where  Perl is not available, for reasons technical,
> > > cultural, or otherwise.  The extensive Perl test suites have also been
> > > ported, and most templates require no or very little modification.

> How does it compare with other "mainstream" Python template engines
> such as Cheetah, Mako, etc. ?

I can't claim a comprehensive familiarity with Python template
offerings, but all of the packages approved for use at my previous
workplace left me cold.  The most popular were ClearSilver and Django,
and both felt horribly limiting compared to the Template Toolkit,
which I became acquainted with when hacking on Bugzilla some years
ago.  Neither supports what I would consider very basic operations on
the template data.  Nothing like the following can be expressed in
those packages:


from pprint import PrettyPrinter
from template import Template

print Template().processString(
  "the list is [% a.pformat(b(c + d)) %]",
  { "a": PrettyPrinter(2, 40), "b": range, "c": 10, "d": 20 }
)


Here we have a template that includes a method call, a function call,
and simple addition.  Neither Django nor ClearSilver can manage any of
these three things.  Both of those packages offer other features not
found in the Template Toolkit; it was the relative impotence of the
templating systems that drove me to attack the translation.

> Unless I missed it, the documentation
> covers the Perl version only.

The online documentation, yes.  All source-level documentation (from
which the online documentation is largely drawn) has been converted
into Python docstrings in the source code.  They can be read by
browsing the Subversion repository or by importing the code and using
help(); eg:

>>> import template.stash
>>> help(template.stash)
... module docs ...
>>> help(template.stash.Stash)
... class docs ...
>>> help(template.stash.Stash.get)
... method docs ...



More information about the Python-list mailing list