On 07-09-18 22:08, Michael F. Stemper wrote: > >> try >> id = xmlmodel.attrib['name'] >> except KeyError: >> id = "constant power" > Never mind! After I continued testing, I realized that the above > should have been written as: > > if 'name' in xmlmodel.attrib: > id = xmlmodel.attrib['name'] > else: > id = "constant power" > > <facepalm>
How about: id = xmlmodel.attrib.get('name', "constant power") -- https://mail.python.org/mailman/listinfo/python-list