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 ofobj
that I'm interested in.obj
is consumed input_item(obj)
inmoduleX.py
, which is also a 3rd-party module.put_item(obj)
originally has GUI code that displaysobj
in a fancy way. However, I want to modify its original behavior such that I can addobj
tomylist
in classStart
and usemylist
later in my own way.Therefore, I cannot pass
Start
reference along the call chain toput_item
since I don't know the call chain and I simply cannot modify it. Also, I cannot change the method signatures inmoduleX.py
otherwise I'll break the original API. What I can change is the content ofput_item(obj)
and thestart.py
.