Say I have a class:
class Foo(object):
def __init__(self):
self.some_attr = ''
self.a_list = []
self.empty_check = bool(self.a_list)
myFoo = Foo()
myFoo.a_list.append(1)
Much like this user, I want empty_check
to change to True
all by itself, without me having to do anything else, as soon as something is appended to the list. As it is above, myFoo.empty_check
is still False
. However, I want mine to go "one way". That is, I don't want myFoo.empty_check = True
to change myFoo.a_list
into []
. (So technically not a duplicate, right?)
How can I accomplish this?
It seems I should be using property setters, but despite googling around for a few hours, including reading up on the linked question, I still don't understand how to do this.