hl7apy icon indicating copy to clipboard operation
hl7apy copied to clipboard

Support default value in getattr

Open iatkinson opened this issue 10 years ago • 2 comments

It would be great to be able to write:

patient_name = message.ORM_O01_PATIENT.PID.PATIENT_NAME
suffix = getattr(patient_name, 'PROFESSIONAL_SUFFIX', '')

rather than having to use hasattr or handle an exception if the attribute is not present.

iatkinson avatar Nov 16 '14 05:11 iatkinson

The root cause seems to be that Element uses return self.children.get(name) in __getattr__ and this throws ChildNotValid exception, which is not an AttributeError.

iatkinson avatar Nov 17 '14 06:11 iatkinson

Hi Ian, you're right. We'll try to put that feature in the next release. Thank you, Vittorio

svituz avatar Nov 17 '14 10:11 svituz