[Zope] CSV or DSV processing

Brad Clements bkc at murkworks.com
Tue Nov 18 09:35:36 EST 2003


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 at 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 at murkworks.com   (315)268-1000
http://www.murkworks.com                          (315)268-9812 Fax
http://www.wecanstopspam.org/                   AOL-IM: BKClements




More information about the Zope mailing list