473,394 Members | 1,735 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Problem of understanding inheritance

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
Dec 6 '06 #1
0 726

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: George Sakkis | last post by:
I'm looking for a design to a problem I came across, which goes like this (no, it's not homework): 1. There is a (single inheritance) hierarchy of domain classes, say A<-B<-..<-Z (arrows point...
5
by: Tony Johansson | last post by:
Hello Experts! I just play around just to try to understand this about multiple inheritance. You have all the class definition below and at the bottom you have the main program. So here I...
4
by: Bangalore | last post by:
Hi, I am not understanding the problem in the below program, #include <iostrema.h> class Base { public: virtual void display() { cout <<"Base \n";
4
by: Bangalore | last post by:
Hi all, I am finding quite difficulty in understanding the behaviour of the following program. Base class is singleton, so it should allow the creation of only one object. Eventhough it is...
9
by: vidalsasoon | last post by:
Ok, this is the structure of my classes. " class Global " | " ------------------------------------------- " | ...
2
by: Ahmed | last post by:
Is it possible for a user control on a webform to access the base class(another webfrom) of the host page ? e.g my code does something like this: ChildPage inherits from ParentPage and a...
9
by: Rudy | last post by:
Hello All! I'm a little confused on Public Class or Modules. Say I have a this on form "A" Public Sub Subtract() Dim Invoice As Decimal Dim Wage As Decimal Static PO As Decimal Invoice =...
6
by: Joel | last post by:
2 Questions: (1) The documentation says application.run() creates a standard message loop on the current thread and "optionally" shows a form. This is really confusing because I was of the...
2
by: VJ | last post by:
I tried to write sample code to get understanding of javascript's prototypal inheritance (along with the variety of function calling choices.. ) During the process, I got myself throughly...
11
by: eBob.com | last post by:
I have this nasty problem with Shared methods and what I think of as "global storage" - i.e. storage declared outside of any subroutines or functions. In the simple example below this "global"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.