Get an attr by calling :meth:`dict.__getitem__`. Like :meth:`__setattr__`, this method converts :exc:`KeyError` to :exc:`AttributeError`. Examples -------- >>> s = Struct(a=10) >>> s.a 10 >>> type(s.get) <... 'builtin_functio
(self, key)
| 123 | raise AttributeError(e) |
| 124 | |
| 125 | def __getattr__(self, key): |
| 126 | """Get an attr by calling :meth:`dict.__getitem__`. |
| 127 | |
| 128 | Like :meth:`__setattr__`, this method converts :exc:`KeyError` to |
| 129 | :exc:`AttributeError`. |
| 130 | |
| 131 | Examples |
| 132 | -------- |
| 133 | |
| 134 | >>> s = Struct(a=10) |
| 135 | >>> s.a |
| 136 | 10 |
| 137 | >>> type(s.get) |
| 138 | <... 'builtin_function_or_method'> |
| 139 | >>> try: |
| 140 | ... s.b |
| 141 | ... except AttributeError: |
| 142 | ... print("I don't have that key") |
| 143 | ... |
| 144 | I don't have that key |
| 145 | """ |
| 146 | try: |
| 147 | result = self[key] |
| 148 | except KeyError: |
| 149 | raise AttributeError(key) |
| 150 | else: |
| 151 | return result |
| 152 | |
| 153 | def __iadd__(self, other): |
| 154 | """s += s2 is a shorthand for s.merge(s2). |
nothing calls this directly
no outgoing calls
no test coverage detected