[Tutor] Style question with classes and modules

Tino Dai tinoloc at gmail.com
Thu Jul 19 21:48:04 CEST 2007


On 7/19/07, Kent Johnson <kent37 at tds.net> wrote:
>
> > The two advantages that I can see are, I don't need to type as much, and
> > there would be a speed up in the execution of code.
>
> Why do you expect a speedup?


In the  Python  Reference by David Beazley on p. 40, he substituted import
math
with from math import sqrt and he switched out d = d + math.sqrt(i) with
sqrt(i). He said that that change made the program run twice as fast.  So
therefore
I was under the impression that "from somemodule import someclass" would
always be
faster than import somemodule.

> Is there a reason why I shouldn't?
>
> If they belong together, put them in a package and use __init__.py. if
> they don't belong together you are just obscuring the design for very
> little savings.


Ok, so I will keep the code as is. Thank you Luke and Kent!

-Tino
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070719/e7b7a008/attachment.htm 


More information about the Tutor mailing list