By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,207 Members | 1,028 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,207 IT Pros & Developers. It's quick & easy.

Overloading __init__ & Function overloading

P: n/a

I am new to python.
I have few questions
a. Is there something like function overloading in python?
b. Can I overload __init__ method

Thanks in advance

regards
prasad chandrasekaran










--- Cancer cures smoking
-----Original Message-----
From: py*********************************************@py thon.org
[mailto:py***************************************** ****@python.org] On
Behalf Of py*****************@python.org
Sent: Friday, September 30, 2005 6:36 PM
To: py*********@python.org
Subject: Python-list Digest, Vol 24, Issue 455

Send Python-list mailing list submissions to
py*********@python.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.python.org/mailman/listinfo/python-list
or, via email, send a message with subject or body 'help' to
py*****************@python.org

You can reach the person managing the list at
py***************@python.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Python-list digest..."

This message contains information that may be privileged or confidentialand is the property of the Capgemini Group. It is intended only for theperson to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive thismessage in error, please notify the sender immediately and delete all copies of this message.

Sep 30 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
I may be reading this question different than Fredrik.

This example is with old-style classes.

class baseclass:
def __init__(self, arg):
#
# Do some initialization
#

def method1(self, arg):
#
# baseclass method goes here
#

class myclass(baseclass):
def __init__(self, arg):
#
# This method gets called when I instantiate this class.
# If I want to call the baseclass.__init__ method I must
# do it myself.
#
baseclass.__init__(arg)

def method1(self, arg):
#
# This method would replace method1 in the baseclass
# in this instance of the class.
#

myObj=myclass(arg)

I could be way off base, but maybe it will help.

-Larry Bates

Iyer, Prasad C wrote:
I am new to python.

I have few questions
a. Is there something like function overloading in python?
b. Can I overload __init__ method

Thanks in advance

regards
prasad chandrasekaran






--- Cancer cures smoking
-----Original Message-----
From: py*********************************************@py thon.org
[mailto:py***************************************** ****@python.org] On
Behalf Of py*****************@python.org
Sent: Friday, September 30, 2005 6:36 PM
To: py*********@python.org
Subject: Python-list Digest, Vol 24, Issue 455

Send Python-list mailing list submissions to
py*********@python.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.python.org/mailman/listinfo/python-list
or, via email, send a message with subject or body 'help' to
py*****************@python.org

You can reach the person managing the list at
py***************@python.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Python-list digest..."

This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message.

Sep 30 '05 #2

P: n/a
Larry Bates wrote:
class myclass(baseclass):
def __init__(self, arg):
#
# This method gets called when I instantiate this class.
# If I want to call the baseclass.__init__ method I must
# do it myself.
#
baseclass.__init__(arg)


This is an example of polymorphism generally, not overloading.
--
Michael Hoffman
Sep 30 '05 #3

P: n/a
Larry Bates wrote:
I may be reading this question different than Fredrik.


it looks like you're using a non-standard definition of the word "overloading".
here are the usual definitions (quoting from a random google page):

"Overloading a method refers to having two methods which share the
same name but have different signatures."

"Overriding a method refers to having a new implementation of a method
with the same signature in a subclass."

</F>

Sep 30 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.