Simple questions on use of objects (probably faq)

Brian Elmegaard brian at rkspeed-rugby.dk
Thu Mar 9 12:24:05 CET 2006


James Stroud <jstroud at ucla.edu> writes:

> You should look into __cmp__ and other magic methods. This is probably
> the type of functionality you seem to be after.

Good example, I need to look at the magic methods.
What I want is to get the value of another variable in C. Would I need to
use __repr__ and get the id from it to find xx of the instance with
maximum x? 

class C:
   def __init__(self, x):
     self.x = x
     self.xx = x*x

sees = [C(x) for x in (4,7,1,3,0,9,2)]  # random-ish ints
print max(sees)

-- 
Brian (remove the sport for mail)
http://www.et.web.mek.dtu.dk/Staff/be/be.html
http://www.rugbyklubben-speed.dk



More information about the Python-list mailing list