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.
Maybe the built-in string interpolation is sufficient?
print "Hello %(name)s" % dict(name="Peter Pan")
diez
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('@')])"
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'
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
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
> 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
Also texttemplate (one of mine):
http://freespace.virgin.net/hamish.sanderson/texttemplate.html
Thanks very much.
> 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
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
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
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.
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