Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python use output from one function in other functions without calling all the other functions

I have one core function that I call from many of the other functions in my script. Problem is that I do not want each function when it calls the core function to run it. Is there a way of storing the output of the core function so that when its called for the second, third time etc its not run?

E.g.

def core_func(a,b,c):
  do something....
  return x,y,z

def func2(a,b,c):
  x,y,z = core_func(a,b,c)
  do something with x,y,z

def func3(a,b,c):
  x,y,z = core_func(a,b,c)
  do something with x,y,z

etc..

func3 here would call core_func again after func2 has called it. How can I prevent that but at the same time use core_func output? A possible solution maybe return the outputs from func2 and use in func3 (but this would get a bit ugly).

Thanks

like image 935
Mark Avatar asked Mar 10 '26 05:03

Mark


1 Answers

variable = core_func(arguments)

func2(variable)

func3(variable)

Store the results of the function in a variable!