[Tutor] line class

Paul McGuire ptmcg at austin.rr.com
Wed Jul 9 03:45:41 CEST 2008


> def length(self):
>      dx,dy = self.p1 - self.p2
>      return (dx**2 + dy **2) ** 0.5

How about:

def length(self):
     return math.hypot( *(self.p1 - self.p2) )

Compiled C code will be much faster than squaring and square rooting.

-- Paul



More information about the Tutor mailing list