Search code examples
datetimepython-2.5

Python time always time at beginning of script?


Code I have written involves getting the time waiting for 10 minutes and then getting the time again, but in both cases datetime.time(datetime.now()) returns the same time and in both cases the time is NOT the time when I ran the part to check the time, its the time that the entire script began to execute

(e.g. if the script starts at 7:05 and at 7:06 i check the time it will tell me its 7:05 etc)


Solution

  • Ah I just realised what was happening, I had the datetime.time(datetime.now()) being passed as the default argument to a method

    def timeTo12Hour(time = datetime.time(datetime.now())):
        etc...
    

    I believe it was getting evaluated at the beginning of the script rather than when I executed the method.