degrees and radians.

Jim Richardson warlock at eskimo.com
Mon May 6 14:40:50 EDT 2002


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 6 May 2002 05:05:38 GMT,
 William Park <opengeometry at NOSPAM.yahoo.ca> wrote:
> 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]
> 


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?


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE81s4yd90bcYOAWPYRAkBWAJ41AnR4O7V84xaT+J6U0p1TyNtowACeOeMo
Zs0TJHmg894Qa353mtLwSbw=
=un2O
-----END PGP SIGNATURE-----

-- 
Jim Richardson
	Anarchist, pagan and proud of it
http://www.eskimo.com/~warlock
Linux, from watches to supercomputers, for grandmas and geeks. 



More information about the Python-list mailing list