[Tutor] custom types question

Thomas Clive Richards thomi at imail.net.nz
Thu Feb 12 00:19:24 EST 2004


> Would a function in the class be good enough for you?
> Something like this?
>
>  >>> class point2D(list):
>
> ...     def __init__(self,X,Y):
> ...         self.x = X
> ...         self.y = Y
> ...     def add(self,p2D):
> ...         self.x += p2D.x
> ...         self.y += p2D.y
> ...
>
>  >>> a = point2D(10,10)
>  >>> b = point2D(5,10)
>  >>> a.add(b)
>  >>> a.x
>
> 15
>
>  >>> a.y
>
> 20
>

Well..... at a pinch.


I sort of feel like you *should* be able to do it, and it should be 
simple...but most of my programming work has been in C/C++, where is is very 
simple.. so maybe that's the way to do it... still...

-- 

Thomi Richards,
thomi at once.net.nz




More information about the Tutor mailing list