Skip to content

Instantly share code, notes, and snippets.

@ehermes
Created September 14, 2016 16:13
Show Gist options
  • Save ehermes/6aefc20a8689de1ebfa48012a2c3f5cb to your computer and use it in GitHub Desktop.
Save ehermes/6aefc20a8689de1ebfa48012a2c3f5cb to your computer and use it in GitHub Desktop.
elif elem.tag == 'parameters':
to_bool = lambda b: True if b == 'T' else False
to_type = {'int': int,
'logical': to_bool,
'string': str,
'float': float,
}
for par in elem.getiterator():
if par.tag in ['v', 'i']:
name = par.attrib['name'].lower()
text = par.text
if text is None:
text = ''
# Floats don't have a 'type' attrib
my_type = to_type[par.attrib.get('type', 'float')]
if par.tag == 'v':
parameters[name] = map(my_type, text.split())
else:
parameters[name] = my_type(text.strip())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment