es ist zum Verzweifeln, ich versteh' es nicht:
Code: Alles auswählen
class TimeRange(datetime):
def __init__(self, year, month, day,
hour=0, minute=0, second=0, microsecond=0, tzinfo=None,
left=0, right=0):
datetime.__init__(self, year, month, day,
hour, minute, second, microsecond, tzinfo)
self.left = self - timedelta(seconds=left*60)
self.right = self + timedelta(seconds=right*60)
Code: Alles auswählen
>>> tr = TimeRange(2011,8,16)
duration.py:6: DeprecationWarning: object.__init__() takes no parameters
hour, minute, second, microsecond, tzinfo)
>>> tr
TimeRange(2011, 8, 16, 0, 0)
>>> tr = TimeRange(2011,8,16,12,15)
>>> tr
TimeRange(2011, 8, 16, 12, 15)
>>> tr = TimeRange(2011,8,16,hour=12,minute=30)
>>> tr
TimeRange(2011, 8, 16, 12, 30)
>>> tr = TimeRange(2011,8,16,hour=12,minute=30,left=10,right=10)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'right' is an invalid keyword argument for this function
- Warum ist 'right' ein ungültiges Schlüsselwort? In welcher '...this function'?? Und wenn schon, dann doch erstmal 'left', oder wo ist das geblieben?
Alles sehr sehr merkwürdig...
Ähnliches funktioniert doch auch:
Code: Alles auswählen
class ExtendedList(list):
def __init__(self, iterable, foo=0):
list.__init__(self, iterable)
self.foo = foo
Code: Alles auswählen
>>> el = ExtendedList((1,2,3))
>>> el
[1, 2, 3]
>>> el.foo
0
>>> el = ExtendedList((4,5,6),20)
>>> el
[4, 5, 6]
>>> el.foo
20