[Bf-python] Python can do operator overloading!

Toni Alatalo antont at kyperjokki.fi
Wed Oct 6 00:54:19 CEST 2004


On Tue, 5 Oct 2004, joeedh wrote:

> Go to http://docs.python.org/lib/operator-map.html, and implement these 
> functions (except as __[func]__) in your class, and you'll have instant 
> operator overloading.  I love python!

:)

soya3d is using these pretty nicely for 3d:
(from the tutorial/basic-4.py, available from
http://home.gna.org/oomadness/en/soya/index.html)
                                                                                
# Lots of Soya methods have also an operator :
#
# Position +  Vector    => Point
# Position += Vector     Position.add_vector(Vector)
# Position >> Position   Position.vector_to (Position) => Vector 
# Position %= CoordSyst  Position.convert_to(CoordSyst)
# Vector   *  float      

# Position +  Vector => Point

# Position += Vector
# Position.add_vector(Vector)
# Translation or vectorial addition (if the Position is a Vector).

# Position >> Position => Vector
# Position.vector_to (Position) => Vector 
# Creates a vector from a strating and an ending position.

# Position %= CoordSyst  Position.convert_to(CoordSyst)
# Vector   *  float      

> joeedh

~Toni




More information about the Bf-python mailing list