degrees and radians.

William Park opengeometry at NOSPAM.yahoo.ca
Mon May 6 16:19:32 EDT 2002


Jim Richardson <warlock at eskimo.com> wrote:
>>     class vector:
>>       def __init__(self, x=[]):               # vector([...])
>>           self.array = x[:]
>>           self.n = len(x)
>> 
>>       def __repr__(self):
>>           return `self.array`
>> 
>>       def __add__(self, other):

	     out = []		<-- missed when I cut/paste... sorry.

>>           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]
>> 
> 
> 
> Thanks. Actually, I am a little intimidated by the whole OO and class
> thing. I still don't "grok" the whole OO thing. 
> 
> I don't understand what the (self,...) part of the init is. I *think* I
> know what __init__ is for, to set up the things you need to use the
> functions (methods?) within the class, but what's with self all over the
> place?

The function is called with parameter 'self' replaced by the object itself.
You can use any function parameter names, but 'self' is used by convention.

-- 
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