I call a method (which is imported from a separate file) multiple times. This method contains a variable whose value I would like to retain between all the times I call the method (without returning it and having it as an argument). For example, I would like to compute a mean of all the values computed across different calls to that function. Is it possible (for example, by making it global or in any other way)?
In file1.py
I make the following import
from file2 import my_method
my_method()
file2.py
contains my_method
def my_method():
#some computation involving variable `a`
return # a is not returned
We would like to retain a
across different calls. The only thing that comes to my mind now is to save the variable a
and read it back every time I call the method.
Note: I can edit file1.py
and file2.py
but I cannot modify the arguments nor the return values of my_method