【发布时间】:2019-11-01 22:37:25
【问题描述】:
我想将对象的所有实例字段转换为属性(仅限 getter),以使它们只读。这些字段可能由子类定义。
我怎样才能做到这一点?
class SomeClass(object):
def __init__(self, foo, bar):
self.foo = foo
self.bar = bar
convert_all_instance_fields_into_properties(self) # implementation ?
【问题讨论】:
标签: python properties python-decorators readonly-attribute