如何在 Python 中“锁定”对象?
说我有:
class Foo:
def __init__(self):
self.bar = []
self.qnx = 10
我会尽可能多地修改 foo :
foo = Foo()
foo.bar.append('blah')
foo.qnx = 20
但是我希望能够“锁定”它,这样当我尝试
lock(foo)
foo.bar.append('blah') # raises some exception.
foo.qnx = 20 # raises some exception.
这在 Python 中可能吗?