function overloading

Jere Kahanpaa kahanpaa at
Thu Jul 3 08:33:38 CEST 2003


Mirko Koenig <koenig at> wrote:
> I serached around the web and some tutorials but i can't finds any
> documentation about function overloading in python.

> I want to have 3 functions:
> def setPos( x, y ):
> def setPos( pos ):
> def setPos( object ):
> ( pos and object are classes i wrote )

The normal Pythonic way is probably as follows:

def setPos(position):
   Set Position. 

   The 'position' argument should be one of
      * a tuple of coordinates (x,y)
      * a instance of class Pos
      * a instance of class Object

   if type(positions) is types.TupleType or type(positions) is types.ListType: 
       x,y = positions
   else if: 
      ... identify object type and process

It's hard to think outside the box when you ARE the box.
                            - unknown, alt.religion.kibology 

More information about the Python-list mailing list