Problem of understanding inheritance
matilda matilda
matilda at grandel.de
Wed Dec 6 18:43:00 EST 2006
Hi all,
I searched for a while, but didn't found answer to my question.
I wrote the following little program:
====================================
#!/usr/bin/python
import datetime as dt
class MyClass(dt.date):
def __init__(self, *args, **kwargs):
super(MyClass, self).__init__(*args, **kwargs)
def addday(self, day=0):
my = self + dt.timedelta(day)
return my
def getfirstofmonth(self):
return self.replace(day=1)
if __name__ == '__main__':
my = MyClass(2006,10,1)
print "Type before", type(my)
my = my.getfirstofmonth()
print "Type after", type(my)
my = my.addday(2)
print "Type after add", type(my)
====================================
What I don't understand is, why the type of the returning object
'my' changes by executing my.addday(2).
Why does addday return the datetime.date-object and not
an object of class MyClass?
What am I missing?
Can anybody clearify?
Thank you in advance.
Best regards
Andreas
More information about the Python-list
mailing list