是否有可能使屬性斷言當它(用於調試的目的)改變了嗎?Python的斷言在屬性設置
class MyClass(object):
def set_my_property(self, value):
self.my_property = value
# TODO: mark my_property so that if it gets set again, an assert
# is triggered
c = MyClass()
c.set_my_property(4)
# any of these lines would cause an assertion
c.set_my_property(8)
c.my_property = 123
你能舉一個你的意思嗎? – 2011-04-24 09:11:06
@jcomeau_ictx:done – 2011-04-24 09:17:59