Python: Classes
Create a new file called point.py and add the following code:
- point.py
class Point(object): """This Class defines a point object in space""" def __init__(self, x = 0, y = 0): self.x = x self.y = y def __str__(self): return str(self.x + self.y)
In your main script file do the following to create a new object:
from point import Point p = Point() print p
The code tells the intepreter to import the Point class from the module point (the file point.py)
More info
See the chapter about Class Objects on the Python website.