Help catching error message

Gnarlodious gnarlodious at gmail.com
Tue Nov 8 08:20:51 EST 2011


What I say is this:

def SaveEvents(self,events):
   try:
      plistlib.writePlist(events, self.path+'/Data/Events.plist') #
None if OK
   except IOError:
      return "IOError: [Errno 13] Apache can't write Events.plist
file"

Note that success returns"None" while failure returns a string.

I catch the error like this:

errorStatus=Data.Dict.SaveEvents(Data.Plist.Events)
if errorStatus: content=errorStatus

It works, but isn there a more elegant way to do it? As in, one line?
I can imagine if success returned nothing then content would remain
unchanged. Isn't there a built-in way to send an error string back and
then catch it as a variable name?

This is Py3 inside WSGI.

-- Gnarlie



More information about the Python-list mailing list