| Python 2.2 für Einsteiger | ||
|---|---|---|
| <<< Previous | Einführung anhand von Beispielen | Next >>> |
#!/usr/bin/python
import time
class Time:
def __init__(self, seconds):
self.seconds = seconds
def __repr__(self):
return time.ctime(self.seconds)
def __add__(self, x):
return Time(self.seconds + x)
__radd__ = __add__ # support for x+t
def __sub__(self, x):
if hasattr(x, 'seconds'): # test if x could be a Time
return self.seconds - x.seconds
else:
return self.seconds - x
now = Time(time.time())
tomorrow = 24*3600 + now
yesterday = now - today
print tomorrow - yesterday # prints 172800
| <<< Previous | Home | Next >>> |
| Python GUI mit GLADE | Up | URL Parser ! |