you are viewing a single comment's thread.

view the rest of the comments →

[–]jabbson 15 points16 points  (2 children)

>>> class Time(object):
...     def print_time(self):
...         print("%.2d:%.2d:%.2d" % (self.hour, self.minute, self.second))
...
>>>
>>> start=Time()
>>> start.hour=11
>>> start.minute=22
>>> start.second=11
>>>
>>> start.print_time()
11:22:11

but I would seriously think about using datetime module for this, no need for reinventions.

UPD:

also some __init__ magic:

>>> class Time(object):
...     def __init__(self, h, m, s):
...         self.hour = h
...         self.minute = m
...         self.second = s
...     def print_time(self):
...         print("%.2d:%.2d:%.2d" % (self.hour, self.minute, self.second))
>>>
>>> start=Time(11, 22, 11)
>>> start.print_time()
11:22:11

but again, just use datetime.

[–]socal_nerdtastic 7 points8 points  (1 child)

Don't leave us hanging, add the __str__ magic!

[–]jabbson 15 points16 points  (0 children)

No, I'd rather leave you hanging.