On Wed, 26 Mar 2008, Steve Litt wrote:
Why not put the preamble and other multiline code in one or more separate
text files. Those things are data, not code. That way you or your
assistant can change the preamble without changing the Python program and
its indentation.
Steve,
Nothing to change that affects indentation. It's analogous to embedding
sql code in a Python docstring; for example,
""" On Insert of a component """
stmt1 = """CREATE TRIGGER fki_comp_cat
BEFORE INSERT ON component
FOR EACH ROW
BEGIN
SELECT CASE
WHEN NEW.comp_cat IS NOT NULL AND
(SELECT cat_name FROM category
WHERE cat_name = NEW.comp_cat) IS NULL
THEN RAISE(ROLLBACK, 'insert on table category violates
foreign key constraint fk_comp_cat')
END
END
"""
self.cur.execute(stmt1)
Writing the preamble lets me write it to the open file in a single
statement. And, everything's in a single module.
Once again, I'd recommend placing the entire template for the report in a
LyX or LaTeX or TeX file, and within that template have placeholders which
the Python program will replace with strings derived from data content. It
would be quick, easy, clean, and very modifiable.
Perhaps. I suspect that it will be easier to read, understand, and debug
when the LaTeX and text flow within the code as they are needed/generated.
For example, what I now have starts with,
def inputVals(self):
Title = self.rptinfo
# General Model Information. This goes on the top of the first page.
stmtA = """SELECT proj_name, proj_desc, model_type, proj_owner,
proj_location, proj_state, lead_agency, keName from
Project"""
self.appData.cur.execute(stmtA)
projData = self.appData.cur.fetchall()
strings_tuple = projData[0]
labName = ['Name: ', 'Description: ', 'Model Type: ', 'Owner: ',
'Location: ', 'State: ', 'Lead Agency: ',
'Knowledge Engineers: ']
self.pg = canvas.Canvas('input_variables.pdf', pagesize=LETTER)
self.pg.setFont('Helvetica-Bold',14)
self.pg.drawCentredString(self.PAGE_SIZE[0]/2.0,self.PAGE_SIZE[1]-180,Title)
self.pg.setFont('Helvetica-Oblique',11)
self.pg.drawCentredString(self.PAGE_SIZE[0]/2.0,self.PAGE_SIZE[1]-198,self.ts)
So the LaTeX code replaces the ReportLab code.
Rich
--
Richard B. Shepard, Ph.D. | Integrity Credibility
Applied Ecosystem Services, Inc. | Innovation
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863