You can specify that you want more information using the info=True argument when calling calculation . This is the approach used by np.unique (with return_inverse and return_index ) and scipy.optimize.leastsq (with full_output parameter):
def calculation(data, max_it=10000, tol = 1e-5, info=False): k = 0 rmse = np.inf while k < max_it and rmse > tol:
Or you can assign additional attributes to the calculation function:
def calculation(data, max_it=10000, tol = 1e-5): k = 0 rmse = np.inf while k < max_it and rmse > tol:
The added information will then be available using
import module d = module.calculation(data) rmse = module.calculation.rmse
Note that this last approach will not work if calculation started from multiple threads at the same time ...
In CPython (due to GIL), only one thread can be executed at any given time, so when you run calculation in several threads, there is little appeal. But who knows? a situation may arise that requires some use of streams on a small scale, for example, in a graphical interface. There access to calculation.k or calculation.rmse may return incorrect values.
Furthermore, Zen of Python says: "Explicit is better than implicit."
Therefore, I would recommend the first approach in the second.
source share