[Tutor] Style question with classes and modules

Terry Carroll carroll at tjc.com
Thu Jul 19 22:44:57 CEST 2007


On Thu, 19 Jul 2007, Kent Johnson wrote:

> Attribute lookup seems to have gotten better since Beazley wrote; here
> is a test program that uses three ways to access math.sqrt - module
> attribute, global name, local name. Note that in the third version, all
> three names (sqrt, d, i) are local:
 . . .
> Sample output:
> 745.465993881
> 561.167001724
> 369.343996048

I'm surprised the difference between the second and third versions is so 
dramatic.  I get a result consistent with that (although you obviously 
have a much faster CPU than I!).

Why is that so much faster?  A smaller namespace to look through?  Or the 
search being short-cut by finding in in the local space and therefore not 
needing to search the global?  Something else?



More information about the Tutor mailing list