Overloading __init__ & Function overloading

Iyer, Prasad C prasad.c.iyer at capgemini.com
Fri Sep 30 10:15:45 EDT 2005


Thanks a lot for the reply.

But I want to do something like this

class BaseClass:
	def __init__(self):
		# Some code over here
	def __init__(self, a, b):
		# Some code over here
	def __init__(self, a, b, c):
		# some code here

baseclass1=BaseClass()
baseclass2=BaseClass(2,3)
baseclass3=BaseClass(4,5,3)




regards
prasad chandrasekaran




















--- Cancer cures smoking

-----Original Message-----
From: Larry Bates [mailto:larry.bates at websafe.com]

Sent: Friday, September 30, 2005 7:39 PM
To: Iyer, Prasad C
Subject: Re: Overloading __init__ & Function overloading

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: python-list-bounces+prasad.c.iyer=capgemini.com at python.org
> [mailto:python-list-bounces+prasad.c.iyer=capgemini.com at python.org] On
> Behalf Of python-list-request at python.org
> Sent: Friday, September 30, 2005 6:36 PM
> To: python-list at python.org
> Subject: Python-list Digest, Vol 24, Issue 455
>

> Send Python-list mailing list submissions to
> 	python-list at 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
> 	python-list-request at python.org
>

> You can reach the person managing the list at
> 	python-list-owner at 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.
>



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.




More information about the Python-list mailing list