Non-web-based templating system

Q

qscomputing

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.
 
D

Diez B. Roggisch

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?

Maybe the built-in string interpolation is sufficient?

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


diez
 
L

Larry Bates

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.

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
 
A

Alex Martelli

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?

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
 
Q

qscomputing

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.
 
J

John Hunter

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
 
F

Fuzzyman

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?

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
 
S

Sybren Stuvel

(e-mail address removed) 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top