Do more imported objects affect performance

Nick Craig-Wood nick at craig-wood.com
Wed Dec 3 04:32:50 EST 2008


On Tue, Dec 02, 2008 at 10:53:47PM -0500, Steve Holden wrote:
> Pardon me for intruding, but timings here are entirely the wrong focus
> for a Python newcomer. Given that imports are super-optimized (i.e. the
> code in the module is only performed once) such a small difference in
> timing is inconsequential, I would suggest.
> 
> As long as "from module import *" is only ever used with modules
> specifically designed to support it, the other forms can be used as
> required. Sure, there is a timing difference between
> 
>   import module
>     ...
>   module.something()
> 
> and
> 
>   from module import something
>     ...
>   something()
> 
> but that's hardly the point. Learning to write sound Python is *much*
> more important that learning to write fast Python, and often the two
> coincide anyway.
> 
> It was true when Kernighan and Plauger wrote it forty years ago and it's
> true now: "First, make it work. Then, *if it doesn't work fast enough*,
> make it work faster".

You are 100% right of course Steve.  I was just trying to answer the
specific question "which is faster" question which probably isn't
helpful for new Python programmers to focus on.

PS I enjoyed your book :-)

-- 
Nick Craig-Wood <nick at craig-wood.com> -- http://www.craig-wood.com/nick



More information about the Python-list mailing list