[Tutor] Contructor Overloading and Function Tooktips

Gooch, John John.Gooch at echostar.com
Tue Apr 19 16:20:00 CEST 2005


I think in the OO world it is called Polymorphism, where you have a single
function name, but multiple definitions that are distinguished from one
another by the number of arguments, type of arguments, and sometimes (
Smalltalk ) the return type of the function.

Here are some example function declarations ( C++ style )
boolean greaterThan( int A, int B );
boolean greaterThan( char A, char B );
boolean greaterThan( double A, double B );

All of these functions are called as "greaterThan( A,B )" and all of them
return a boolean "true" or "false" value, but the compiler decides which one
of the three functions above gets called depending on the data type of A and
B. My first question was whether or not you can do this in Python with the
__init__ function. In C++ you can have multiple contructors for a class,
with the arguments deciding which contructor is called. Here is an example:

class Circle : Shape {
	Circle();//creates default circle object

	Circle( int x, int y, float radius ); //creates circle object with
specified x,y coordinates and radius

now, replace 'Circle' in the 'public:' area with '__init__' and you have a
picture of what I would like to do in Python, but I don't know if the
language support it or not. 

Thank you for answering the second part of the question, I will try that
technique out.

John A. Gooch
Systems Administrator
IT - Tools
EchoStar Satellite L.L.C.
9601 S. Meridian Blvd.
Englewood, CO  80112
Desk: 720-514-5708 

-----Original Message-----
From: Brian van den Broek [mailto:bvande at po-box.mcgill.ca] 
Sent: Friday, April 15, 2005 4:22 PM
To: Gooch, John
Cc: Python tutor
Subject: Re: [Tutor] Contructor Overloading and Function Tooktips

Gooch, John said unto the world upon 2005-04-15 18:03:
> I have a couple of questions:
> Is there a way to create multiple __init__ routines in a Python Class?

Hi John,

I'm not sure what you mean by that. Could be me, or could be the 
question. :-)

> Secondly, I cannot remember how to make it so that when you start 
> typing in a defined function name, it pops up a tooltip showing the
functions syntax.
> 	ex: def delRecord( some params ):
> 	dr = delRecord()
> 	dr.someCommand( <-- tooltip popups up here

Many Python-aware editors use the first line of the docstring to 
construct the tooltip:

def silly():
     '''This will be the tooltip.

     This will be more documentation.'''


Brian vdB

More information about the Tutor mailing list