Skip to content
Snippets Groups Projects
Commit 3b228698 authored by Jameson Graef Rollins's avatar Jameson Graef Rollins
Browse files

struct: getitem handles key as nested item

e.g. ifo['Sub.Element']
parent e548e6f9
No related branches found
No related tags found
1 merge request!17Quantum quadrature noise
......@@ -75,8 +75,15 @@ class Struct(object):
##########
def __getitem__(self, item):
return self.__dict__[item]
def __getitem__(self, key):
"""Get a (possibly nested) value from the struct.
"""
if '.' in key:
k, r = key.split('.', 1)
return self.__dict__[k][r]
else:
return self.__dict__[key]
def __setitem__(self, item, value):
self.__dict__[item] = value
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment