Where to import modules?
gh at ghaering.de
Fri Sep 26 14:46:20 CEST 2003
Andreas Neudecker wrote:
> I have a "style" question: Sometimes, modules will only be used in a
> particular, optional, part of a program (function, class), that will not
> always be used when the application is run. So I think it is better to
> import them only there, not on the top of the file (together with the
> other imports). Is that okay, or are there good reasons for not doing so?
That's perfectly ok, if you want/need to optimize your program startup
time. It might also save a byte or two of memory, depending on how large
the module is.
More information about the Python-list