Perl to Python: Classes

Define a class:

class MyClass:
        “Doc string“
        def __init__(self):
                self.data = []
        def mymethod(self):
                return “Yop“

Instantiate the class:

whatever = MyClass()

Call other methods of the class from within the class:

self.othermethod(42)

An inherited class:

class DerivedClass(BaseClass): ...

A minimal class that gets parameters assigned:

class Point:
   pass

mypoint = Point()
mypoint.x = 1.0
mypoint.y = 2.5

Overloadable operators:

+

class.add

-

class.sub

*

class.mult

/

class.div

str

class.str

< > ==

class.cmp

WorkaroundOrg: PerlToPython/Classes (last edited 2005-08-29 18:00:12 by ChristophHaas)