Problem of understanding inheritance

  • Thread starter matilda matilda
  • Start date
M

matilda matilda

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top