degrees and radians.
William Park
opengeometry at NOSPAM.yahoo.ca
Mon May 6 01:05:38 EDT 2002
Jim Richardson <warlock at eskimo.com> wrote:
> sorry, I wasn't very clear, in the above example, the result I am
> looking for is
>
>>>>a=(1,2)
>>>>b=(2,3)
>>>>a+b
> (3,5)
Well, you can learn about Python's OO nature by writing class to handle
this:
class vector:
def __init__(self, x=[]): # vector([...])
self.array = x[:]
self.n = len(x)
def __repr__(self):
return `self.array`
def __add__(self, other):
for a, b in map(None, self.array, other.array):
out.append(a + b)
return vector(out)
>>> a = vector([1,2])
>>> b = vector([2,3])
>>> a+b
[3, 5]
--
William Park, Open Geometry Consulting, <opengeometry at yahoo.ca>
8-CPU Cluster, Hosting, NAS, Linux, LaTeX, python, vim, mutt, tin
More information about the Python-list
mailing list