0
我已經注意到,在某些語言中,例如clojure,您可以將元數據分配給對象。python中的元數據
在Python中,你也可以做這樣的事情。
class meta_dict(dict):pass
a={'name': "Bill", 'age':35}
meta_a = meta_dict(a)
meta_a.secret_meta_data='42'
meta_a==a
True
secret_meta_data_dict=meta_a.__dict__
original_dict=dict(meta_a)
我在想,如果這是一個合理的模式,當你需要有特定形式的數據,但需要一些其他數據優雅地跟着一起跟隨。
你可能會考慮這個答案http://stackoverflow.com/a/27783928/2823755 – wwii 2015-01-05 17:43:55