473,406 Members | 2,956 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,406 software developers and data experts.

Overloading __init__ & Function overloading


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
3 2868
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Terje Slettebø | last post by:
To round off my trilogy of "why"'s about PHP... :) If this subject have been discussed before, I'd appreciate a pointer to it. I again haven't found it in a search of the PHP groups. The PHP...
1
by: Fuzzyman | last post by:
I've been programming in python for a few months now - and returning to programming after a gap of about ten years I've really enjoyed learning python. I've just made my first forays into...
2
by: Sergey Krushinsky | last post by:
Hello all, Is there a common way to emulate constructor overloading in Python class? For instanse, I have 3 classes: 1/ Polar - to hold polar coordinates; 2/ Cartesian - to hold cartesian...
7
by: Doran_Dermot | last post by:
Hi All, I've seen lots of code in which the attributes of a class are accessed and modified using two separate methods. For example: class Problems: def __init__( self, refNum ):...
9
by: Martin Häcker | last post by:
Hi there, I just tried to run this code and failed miserably - though I dunno why. Could any of you please enlighten me why this doesn't work? Thanks a bunch. --- snip --- import unittest...
4
by: John M. Gabriele | last post by:
I know that Python doesn't do method overloading like C++ and Java do, but how am I supposed to do something like this: --------------------- incorrect ------------------------...
11
by: placid | last post by:
Hi all, Is it possible to be able to do the following in Python? class Test: def __init__(self): pass def puts(self, str): print str
9
by: sturlamolden | last post by:
Python allows the binding behaviour to be defined for descriptors, using the __set__ and __get__ methods. I think it would be a major advantage if this could be generalized to any object, by...
4
by: Benny the Guard | last post by:
Working on a class that I would use multiple constructors in C++ since I have different ways of creating the data. Tried this in python by defining multiple __init__ methods but to no avail, it...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.