I want to read and parse CSV files ( and output CSV files but I can probably do that myself) in a Python script for my Zope site. Any hints on the best strategy? I see a number of Python modules around doing CSV or DSV processing. Would the best strategy be to turn those into an external python method? Is there something around ready to go? What modules have others used successfully?
Brian Sullivan wrote at 2003-11-17 11:35 -0500:
I want to read and parse CSV files ( and output CSV files but I can probably do that myself) in a Python script for my Zope site.
Any hints on the best strategy? I see a number of Python modules around doing CSV or DSV processing. Would the best strategy be to turn those into an external python method? Is there something around ready to go? What modules have others used successfully?
Either you use them in External Methods or you provide the necessary security declarations (--> "Products/PythonScripts/README.txt"). -- Dieter
On 17 Nov 2003 at 11:35, Brian Sullivan wrote:
I want to read and parse CSV files ( and output CSV files but I can probably do that myself) in a Python script for my Zope site.
I used the CSV.py module and developed a stand-alone .py module to do the necessary processing. Then, I created an external method that loads this module and passes in the request file object. So, I can debug the csv processing outside of Zope and get everything working, then hook it into Zope. It's pretty easy. -- Brad Clements, bkc@murkworks.com (315)268-1000 http://www.murkworks.com (315)268-9812 Fax http://www.wecanstopspam.org/ AOL-IM: BKClements
I want to read and parse CSV files ( and output CSV files but I
can
probably do that myself) in a Python script for my Zope site.
I used the CSV.py module and developed a stand-alone .py module to do the necessary processing.
Where is this CSV.py module that you used ?(http://www.object-craft.com.au/projects/csv/ ?) I also found this - http://python-dsv.sourceforge.net/ -- I don't know if it is better or not.
Then, I created an external method that loads this module and passes in the request file object.
So, I can debug the csv processing outside of Zope and get everything working, then hook it into Zope. It's pretty easy.
Is the external method you created available somewhere?
On 17 Nov 2003 at 14:07, Brian Sullivan wrote:
Where is this CSV.py module that you used ?(http://www.object-craft.com.au/projects/csv/ ?)
I also found this - http://python-dsv.sourceforge.net/ -- I don't know if it is better or not.
Oh I don't remember where it came from. # CSV 0.17 8 June 1999 Copyright ?Laurence Tratt 1998 - 1999 # e-mail: tratt@dcs.kcl.ac.uk # home-page: http://eh.org/~laurie/comp/python/csv/index.html # It doesn't really matter, it's just a module that takes either a file object or a path to a file and returns another object you can use to iterate rows as dict-like items.
Is the external method you created available somewhere?
No, since it's highly specific to the task.. Processing UPS WorldShip data. Perhaps the code from the Extension method would be helpful.. here it is. SQL_InsertEventLog is a PythonScript in Zope that's obtained through acquisition via self. In this example, I write the uploaded file data to a temporary file, then pass that temp file path to the "other module". The code is from 1.5.2, hence I don't use string methods in it. def UploadUPSExtract(self,REQUEST): """Upload UPS extract file from form""" f = REQUEST.form['ExtractFile'] fname = tempfile.mktemp() of = open(fname,'wb') of.write(f.read()) del of cnt, report = ProcessShipments.LoadUPSShipments(inputFile=fname,db=GetDB()) try: os.remove(fname) except: pass res = "Uploaded "+str(cnt)+" packages<br>\n" if report: res = res + '<b>The following errors were found:</b><br>' + string.join(string.split(report,'\n'),'<br>\n') try: note = 'Uploaded %d packages' % cnt if report: note = note + ' with %d errors' % len(string.split(report,'\n')) self.SQL_InsertEventLog(peopleid=REQUEST.xpeopleid,eventtype='UPS Upload',note=note) except: traceback.print_exc() print "self is ",repr(self) return res -- Brad Clements, bkc@murkworks.com (315)268-1000 http://www.murkworks.com (315)268-9812 Fax http://www.wecanstopspam.org/ AOL-IM: BKClements
participants (3)
-
Brad Clements -
Brian Sullivan -
Dieter Maurer