class NameSpace():
pass
foo = NameSpace()
foo
<__main__.NameSpace at 0x7f1f881b0cf8>
def show_names(thing):
return [name for name in dir(thing) if not name.startswith('__')]
show_names(foo)
[]
foo.hello = 'world'
foo.bar = 3.1415926
show_names(foo)
['bar', 'hello']
getattr(foo, 'hello')
'world'
getattr(foo, 'bar')
3.1415926
getattr(foo, 'world')
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-10-a09ebb842f14> in <module>() ----> 1 getattr(foo, 'world') AttributeError: 'NameSpace' object has no attribute 'world'