RE: Python question

 

 

 

You could just pass in self if you have to have two variables but I don't
know why you need the two variables because you could do

 

t.isAfter(t1)

 

If you have to have two variables you should move the isAfter function out
of the class and have it accept your time class as arguments so you could
just call it like

 

isAfter(t,t1)

 

 

 

Of course the problem is your function will not work because you need to
individually compare all of the hour, minute, and seconds of the first time
with that of the second time so the function would have to be changed to
work.

 

 

 

From: programmingblind-bounce@xxxxxxxxxxxxx
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of edward
Sent: Saturday, November 21, 2009 7:48 PM
To: programmingblind@xxxxxxxxxxxxx
Subject: Python question

 

hello all 

I am trying to check if one time comes immediately after another.  I wrote a
method called isAfter.  the problem is how do I use it.  meaning to use a
method in python the syntax is x.isAfter but I have two  variables not one.
so I need to x's.

 

edward

code starts

class WhatTime:
 def __init__(self, hour,minute,second):
  self.second=second
  self.minute=minute
  self.hour=hour

 

 def isAfter(self,t1,t2):
  check=t2-t1
  return 1 in check
 def __str__(self):
  return "the time is: "+str(self.hour)+":"+str(self.minute)+"
"+str(self.second)

 

t=WhatTime(10,25,43)
print t
t1=WhatTime(10,12,13)
t2=WhatTime(10,12,14)
isAfter

GIF image

Other related posts: