def GetXML(self, Elem):
if issubclass(type(Elem), ElementTree.Element):
try:
self.Title = Elem.attrib['Title']
except KeyError:
pass
try:
self.Content = Elem.find('Content').text.strip()
except AttributeError:
pass
try:
self.Date = Elem.attrib['Date']
except KeyError:
pass
else:
raise TypeError("Elem must be of type xml.etree.ElementTree.Element")
I'm using Python 3.2 and if the element or attribute doesn't exist it's no big deal we can keep working so I just pass through the errors. But my question is there a way to put these into one try except block that if one line throws the error it just keeps going through the next one?
So something like this, I know this wouldn't work but just to try and explain what I'm looking for...
try:
self.Title = Elem.attrib['Title']
self.Content = Elem.find('Content').text.strip()
self.Date = Elem.attrib['Date']
except (AttributeError, KeyError):
continue
Does anything like this exist in python?
Thanks

New Topic/Question
Reply



MultiQuote



|