Compile Cheetah Template on Windows

Tim Roberts timr at probo.com
Fri Nov 30 00:00:59 EST 2007


brianrpsgt1 <brianlong at cox.net> wrote:

>Tim, thank you very much for the reply.  The 'cheetah' function is now
>working!
>
>I am still having a problem creating the file.  I continually get
>errors.  I am sure that it is something very simple.
>
>Below is the code, please guide me in the right direction.... ::
>
>import psycopg2, psycopg2.extensions
>from Cheetah.Template import Template
>import operator
>import os
>from SafetyNet import SafetyNet
>
>filename = open("C:\Python25\Lib\site-packages\PSN
>\InstalledDevices.html")

There are three problems here.  First, you have bare backslashes in this
string.  You happened to get lucky with this one, but if your file had been
called "...\textfile.html", it would have failed because \t is the "tab"
character.  You need to either:
  1. Double all the backslashes (...25\\Lib\\site-...)
  2. Use a raw string (open(r"C:\Python25...))
  3. Use forward slashes (open("C:/Python25/Lib/site-..."))

Second, later on you try to write to this file, but you have opened it in
"read" mode.

Third, you should not be doing your development work inside the Python
site-packages directory.  The only thing in there should be the files from
the add-on packages you have installed.  Remember that, when you upgrade,
the site-packages folder will go away.

You need:
  filename = open("C:/Development/InstalledDevices.html", "w")

>pocmonitors_cur = db.cursor()
>pocmonitors_cur.execute("""SELECT pocmonitor_name, pocmonitor_sn FROM
>pocmonitor ORDER BY pocmonitor_name""")
>
>pocmonitors = []
>
>for i in range(pocmonitors_cur.rowcount) :
>    pocmonitors.append(pocmonitors_cur.fetchone())
>pocmonitors_cur.close()
>db.close()

What are you trying to do here?  If you just want to turn the query results
into a list, you can just do:

    pocmonitors = pocmonitors_cur.fetchall()

>output = Template(file='C:\Python25\Lib\site-packages\PSN
>\SafetyNet.tmpl', searchList=[nameSpace])

This string also needs to be escaped.
-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



More information about the Python-list mailing list