----- Original Message ----- From: "Garry Saddington" <[EMAIL PROTECTED]>
To: <zope@zope.org>
Sent: Monday, April 14, 2008 3:19 PM
Subject: [Zope] try clause in external method

I have the following external method which takes an input .csv file and enters the data into a database by calling a ZSQL method. There may be errors in the
input file and so I am trying to catch them and insert each bad row in a
different table. The errors are detected by table constraints on the table
definition and should be reported by the Psycopg connector. However no
correct rows are entered and only the last error row is entered. Can anyone
see what I am doing wrong in this script?

def timetabler(self,REQUEST):
 import csv,string
 from cStringIO import StringIO
 r =
csv.DictReader(filebody("day","periodstart","periodend" ,"year","teachgroup","teacher" ,"subject" ,"set" ,"room"))
 for row in r:
 return self[dtmlMethodName](self,self.REQUEST)

A couple of things...

1) Have bare try/except clauses may cause you grief ;-)

2) When an error is trapped by the 'try' statement the transaction is not committed (ie. nothing is written to your db), only the 'except' statement is executed.

Zope maillist  -  Zope@zope.org
**   No cross posts or HTML encoding!  **
(Related lists - http://mail.zope.org/mailman/listinfo/zope-announce
http://mail.zope.org/mailman/listinfo/zope-dev )

Reply via email to