【发布时间】:2016-09-06 18:35:10
【问题描述】:
以下方法似乎都适用。使用types.SimpleNamespace 有什么优势(除了漂亮的repr)?还是一样的?
>>> import types
>>> class Cls():
... pass
...
>>> foo = types.SimpleNamespace() # or foo = Cls()
>>> foo.bar = 42
>>> foo.bar
42
>>> del foo.bar
>>> foo.bar
AttributeError: 'types.SimpleNamespace' object has no attribute 'bar'
【问题讨论】:
标签: python python-3.x