This was discussed only days ago:
http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/41a6c0e1e260cd72/fc1c924746532316?q=multiple+constructors+python&_done=%2Fgroups%3Fq%3Dmultiple+constructors+python%26&_doneTitle=Back+to+Search&&d#fc1c924746532316
-Don
John M. Gabriele wrote:
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 ------------------------ #!/usr/bin/python
class Point3d: pass
class Vector3d: """A vector in three-dimensional cartesian space."""
def __init__( self ): """Create a Vector3d with some reasonable default value.""" x, y, z = 0.0, 0.0, 0.0
def __init__( self, x_from, y_from, z_from, x_to, y_to, z_to ): """Create a Vector3d from x-y-z coords.""" # ... pass
def __init__( self, point_from, point_to ):
"""Create a Vector3d from two Point3d objects."""
# ...
pass
def __init__( self, same_as_this_vec ): """Create a Vector3d from a copy of another one.""" # ... pass
p = Point3d()
p2 = Point3d()
# v = Vector3d( p2, p ) -- Nope. Only the last __init__() counts.
---------------------- /incorrect -------------------------------
Thanks.
-- http://mail.python.org/mailman/listinfo/python-list