I have this start.py:
# start.py
class Start:
def __init__(self):
self.mylist = []
def run(self):
# some code
Executing its run() method will at some point invoke the put_item(obj) method in moduleX.py:
# moduleX.py
def put_item(obj):
# what should I write here
run() is NOT the direct caller of put_item(obj). In fact, from run() to put_item(obj) the execution is quite complex and involves a lot of other invocations.
My problem is, when put_item(obj) is called, can I directly add the value of obj back to mylist in the class Start? For example:
s = Start()
# suppose during this execution, put_item(obj) has been
# invoked 3 times, with obj equals to 1, 2, 3 each time
s.run()
print(s.mylist) # I want it to be [1,2,3]
UPDATE:
From
run()toput_item(obj)the execution involves heavy usages of 3rd-party modules and function calls that I have no control over. In other words, the execution inbetweenrun()toput_item(obj)is like a blackbox to me, and this execution leads to the value ofobjthat I'm interested in.objis consumed input_item(obj)inmoduleX.py, which is also a 3rd-party module.put_item(obj)originally has GUI code that displaysobjin a fancy way. However, I want to modify its original behavior such that I can addobjtomylistin classStartand usemylistlater in my own way.Therefore, I cannot pass
Startreference along the call chain toput_itemsince I don't know the call chain and I simply cannot modify it. Also, I cannot change the method signatures inmoduleX.pyotherwise I'll break the original API. What I can change is the content ofput_item(obj)and thestart.py.