0
我有下面的代碼,在我所處理異常2個陳述,如何在Python中使用嵌套try/catch?
2號線和4號線
if(re.search("USN:.*MediaRenderer", datagram, flags=re.IGNORECASE)):
deviceXML = re.search("LOCATION:(.*.xml)", datagram, flags=re.IGNORECASE).group(1) # this line
root = ElementTree.fromstring(urllib2.urlopen(XMLLocation).read())
friendlyName = root.find('.//{}friendlyName'.format(Server.namespace)).text # this line
if not friendlyName in deviceList.keys():
deviceList[friendlyName] = host
self.model.setStringList(deviceList.keys())
如何使用嵌套的try/catch這裏
我嘗試以下方法:
if(re.search("USN:.*MediaRenderer", datagram, flags=re.IGNORECASE)):
try:
deviceXML = re.search("LOCATION:(.*.xml)", datagram, flags=re.IGNORECASE).group(1)
root = ElementTree.fromstring(urllib2.urlopen(XMLLocation).read())
try:
friendlyName = root.find('.//{}friendlyName'.format(Server.namespace)).text
print "\n fname = ", friendlyName
if not friendlyName in deviceList.keys():
deviceList[friendlyName] = host
self.model.setStringList(deviceList.keys())
except:
pass
這是給我的縮進錯誤,除了線
除了不給我任何o/p – Patrick
@Patrick什麼是「o/p」? –
@ ron.rothman輸出 – Midnighter