Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Non-web-based templating system

2 views
Skip to first unread message

qscom...@gmail.com

unread,
Apr 28, 2006, 6:55:57 AM4/28/06
to
Hi,

I'm creating a small application in Python that uses lists and
dictionaries to create a rudimentary database. I'd like to create some
"fill-in-the-blanks" reports from this data, ideally by taking an RTF
or plaintext file as a template and replacing placeholder tags with my
data.
Are there any good pre-written systems that would allow me to do this?

Thanks,
- QS Computing.

Diez B. Roggisch

unread,
Apr 28, 2006, 7:22:20 AM4/28/06
to
qscom...@gmail.com wrote:

Maybe the built-in string interpolation is sufficient?

print "Hello %(name)s" % dict(name="Peter Pan")


diez

bruno at modulix

unread,
Apr 28, 2006, 8:13:25 AM4/28/06
to

Else you may want to look at:
- http://www.python.org/doc/2.4.2/whatsnew/node5.html
- empy : http://www.alcyone.com/pyos/empy/
- cheetah : http://www.cheetahtemplate.org/

HTH
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'on...@xiludom.gro'.split('@')])"

qscom...@gmail.com

unread,
Apr 28, 2006, 8:53:16 AM4/28/06
to
Thanks, it looks like empy is what I need.

Brett g Porter

unread,
Apr 28, 2006, 9:09:31 AM4/28/06
to pytho...@python.org
Diez B. Roggisch wrote:
> qscom...@gmail.com wrote:
>
> Maybe the built-in string interpolation is sufficient?
>
> print "Hello %(name)s" % dict(name="Peter Pan")


Or in recent pythons, the built-in string templating system (see
http://docs.python.org/lib/node109.html)


>>> from string import Template
>>> d = dict(name="Barney")
>>> s = Template("Hello $name")
>>> s.substitute(d)
'Hello Barney'

Larry Bates

unread,
Apr 28, 2006, 10:12:37 AM4/28/06
to

It may be overkill for your application but if you are looking for
high quality .PDF output this combination works:

ReportLab PageCatcher - reads .PDF background templates (note: not free)
ReportLab - allows you to write on top of the .PDF template to produce
a .PDF file as output.

The results are a very high quality .PDF output document.

-Larry Bates

Alex Martelli

unread,
Apr 28, 2006, 11:11:11 AM4/28/06
to
<qscom...@gmail.com> wrote:

I have a certain fondness for the first over-100-lines module I wrote
for Python, which eventually resulted in:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52305

and while I haven't checked its descendant:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/465508

it may have important enhancements. There are also a couple of
variations on the web that are specialized for XML and HTML (search for
yaptu), but the generic one should work better for RTF and TXT.


Alex

Erik Max Francis

unread,
Apr 28, 2006, 4:43:24 PM4/28/06
to
qscom...@gmail.com wrote:

> Thanks, it looks like empy is what I need.

:-)

--
Erik Max Francis && m...@alcyone.com && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
The object of war is not to die for your country but to make the
other bastard die for his. -- Gen. George Patton

has

unread,
Apr 28, 2006, 8:06:49 PM4/28/06
to

qscom...@gmail.com

unread,
Apr 29, 2006, 1:57:23 AM4/29/06
to
Actually, that looks even better that EmPy for what I need. I will try
out these suggestions and then see what seems best.

Thanks very much.

Erik Max Francis

unread,
Apr 29, 2006, 2:04:08 AM4/29/06
to
qscom...@gmail.com wrote:

> Actually, that looks even better that EmPy for what I need.

:-(

--
Erik Max Francis && m...@alcyone.com && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis

All bad poetry springs from genuine feeling.
-- Oscar Wilde

John Hunter

unread,
May 1, 2006, 11:54:36 PM5/1/06
to
>>>>> "Alex" == Alex Martelli <ale...@yahoo.com> writes:

Alex> I have a certain fondness for the first over-100-lines
Alex> module I wrote for Python, which eventually resulted in:

As well you should! YAPTU powers the entire matplotlib website
(screenshots, FAQ, what's new, etc), as evidenced by the "Powered by
YAPTU" co-branding on the bottom of every page

http://matplotlib.sf.net

with src (*.html.template) at

http://svn.sourceforge.net/viewcvs.cgi/matplotlib/trunk/htdocs/

I must confess though that the prehistoric YAPTU version I use comes
in at only 78 lines, so it is clearly time for me to upgrade. I rely
on it so much I even wrote a debian ubuntu package for local use, as
twisted as that may seem. I definitely need to check out the latest
version!

JDH

Fuzzyman

unread,
May 2, 2006, 5:27:09 AM5/2/06
to

Another option is the 'embedded_code.py' module used by `Firedrop2
<http://www.voidspace.org.uk/python/firedrop2/>`_ and `rest2web
<http://www.voidspace.org.uk/python/rest2web/>`_.

It takes a text string as input and a namespace (dictionary) as input
and returns a text string.

It replaces single placeholders of the form :

<% name %>

It also executes chunks of embedded code in the namespace, and replaces
them with whatever the code prints to stdout. These are of the form :

<#
print name
if name2.startswith('something'):
print name2
#>

This is very useful for simple templating.

All the best,

Fuzzyman
http://www.voidspace.org.uk/python/shareware.shtml


> Thanks,
> - QS Computing.

Sybren Stuvel

unread,
May 2, 2006, 6:41:20 AM5/2/06
to
qscom...@gmail.com enlightened us with:

> I'm creating a small application in Python that uses lists and
> dictionaries to create a rudimentary database. I'd like to create
> some "fill-in-the-blanks" reports from this data, ideally by taking
> an RTF or plaintext file as a template and replacing placeholder
> tags with my data.

I'd go for Cheetah: http://www.cheetahtemplate.org/

Sybren
--
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself?
Frank Zappa

0 new messages