Overloading __init__ & Function overloading

I

Iyer, Prasad C

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: [email protected]
[mailto:p[email protected]] On
Behalf Of (e-mail address removed)
Sent: Friday, September 30, 2005 6:36 PM
To: (e-mail address removed)
Subject: Python-list Digest, Vol 24, Issue 455

Send Python-list mailing list submissions to
(e-mail address removed)

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
(e-mail address removed)

You can reach the person managing the list at
(e-mail address removed)

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.
 
L

Larry Bates

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
 
M

Michael Hoffman

Larry said:
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.
 
F

Fredrik Lundh

Larry said:
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>
 

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

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,816
Latest member
nipsseyhussle

Latest Threads

Top