While attempting to optimize my current code, I have this situation where my function by default gets the current time, and it was done using a very basic, and not elegant way:
from datetime import datetime
.
.
.
def generateGraph(self, fromTime, toTime = None):
if toTime is None:
toTime = datetime.now()
.
.
Thus, I had started testing going with something such as this:
def generateGraph(self, fromTime, toTime = datetime.now()):
.
.
However, since my application was a little large (and the slight difficulty of testing this application specifically) I made a short code snippet that I have tested, as follows:
X = 20
def setValue():
return X
def myFunction(value=setValue()):
print(value)
a = myFunction()
X = 15
b = myFunction()
I expected the output to be: 20 15
However, I had the output as: 20 20
Is this value being assigned during the function declaration? Or is it assigned at the moment the "def" statement is being read? I am a bit unclear on how this might affect my application, and how in this example code snippet, I can achieve what I am looking for (Since I used X just as a replacement for datetime.now(), for simplicity/visibility sake).