2011/2/17 Chris Rebert <c...@rebertia.com>

> Yes, of course. Importing a module multiple times (as would happen if
> fun() is called multiple times) is obviously slower than just
> importing it once, although the 2nd and subsequent imports will be
> faster as Python will just return another reference to the previously
> imported instance of the module rather than importing it again from
> scratch. There are also local variable vs. module-global variable
> speed differences involved.
>
> However, "Premature optimization is the root of all evil." Have you
> checked whether the imports are taking a significant amount of
> execution time? Odds are that they aren't. When optimizing, do so on
> the basis of empirical data; run your program under a profiler, and
> let the results guide your optimization process.
>
> Cheers,
> Chris
> --
> http://blog.rebertia.com


Well no I wasn't really worried about performances.
I just thought that if an external module is really almost never used, it
might make sense to import it only when it's really needed.

Anyway if it's against the holy pep8 then it's fine :)
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to