Overloading __init__ & Function overloading

Discussion in 'Python' started by Iyer, Prasad C, Sep 30, 2005.

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

    Send Python-list mailing list submissions to


    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


    You can reach the person managing the list at


    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.
    Iyer, Prasad C, Sep 30, 2005
    #1
    1. Advertising

  2. Iyer, Prasad C

    Larry Bates Guest

    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=
    > [mailto:python-list-bounces+prasad.c.iyer=] On
    > Behalf Of
    > Sent: Friday, September 30, 2005 6:36 PM
    > To:
    > Subject: Python-list Digest, Vol 24, Issue 455
    >
    > Send Python-list mailing list submissions to
    >
    >
    > 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
    >
    >
    > You can reach the person managing the list at
    >
    >
    > 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.
    >
    Larry Bates, Sep 30, 2005
    #2
    1. Advertising

  3. 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
    Michael Hoffman, Sep 30, 2005
    #3
  4. 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>
    Fredrik Lundh, Sep 30, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steven Bethard
    Replies:
    2
    Views:
    445
    Steven Bethard
    Feb 16, 2005
  2. Fredrik Lundh
    Replies:
    0
    Views:
    438
    Fredrik Lundh
    Sep 30, 2005
  3. Steve Holden
    Replies:
    0
    Views:
    422
    Steve Holden
    Sep 30, 2005
  4. Iyer, Prasad C
    Replies:
    4
    Views:
    570
    John J. Lee
    Sep 30, 2005
  5. Fredrik Lundh
    Replies:
    0
    Views:
    391
    Fredrik Lundh
    Sep 30, 2005
Loading...

Share This Page