E.g., I have:
def readDb():
# Fetch a lot of data from db, spends a lot time
...
return aList
def calculation():
x = readdb()
# Process
def readDb():
... #Fetch a lot of data from db, spends a lot time
return aList
def calculation(data):
x=data
...process x...
return y
data = readDb()
calculation(data)
calculation(data)
calculation(data)
This will only hit the database once.
Basically, you want to save the results of readDb() to a seperate variable which you can then pass to calculation().