Feb-01-2019, 06:04 PM
(This post was last modified: Feb-01-2019, 06:04 PM by MuntyScruntfundle.)
Hi folks.
From what I can find on how to compare dates, basically use the < and >, and how to put a class structure together, the following should work. But it doesn't. If I check more than or less than the tripped routine is always returning True. Is this because it's trying to return an object rather than a value??? And why does get dates return ,bound method customer.getsdates blah blah 0x0blahblah?
What am I misunderstanding?
Many thanks.
From what I can find on how to compare dates, basically use the < and >, and how to put a class structure together, the following should work. But it doesn't. If I check more than or less than the tripped routine is always returning True. Is this because it's trying to return an object rather than a value??? And why does get dates return ,bound method customer.getsdates blah blah 0x0blahblah?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
import datetime import time class clstimer: def __init__( self , interval): self .interval = interval self .startdate = datetime.datetime.now() def tripped(): nowdate = datetime.datetime.now() checkdate = self .startdate + datetime.timedelta(seconds = self .interval) if nowdate>checkdate: self .startdate = datetime.datetime.now() return True else : return False def getdates(): nowdate = datetime.datetime.now() checkdate = self .startdate + datetime.timedelta(seconds = self .interval) return str (nowdate), str (checkdate) def main(): tmr = clstimer( 5 ) print (tmr.getdates) while True : if tmr.tripped: print ( "Tripped" ) else : print ( "Nope" ) time.sleep( 1 ) main() |
Many thanks.