Where should 'import' statement be put?

Sean 'Shaleh' Perry shalehperry at attbi.com
Tue Apr 16 12:08:56 EDT 2002


> 
> I believe imports are done only once regardless of the number of times
> the statement appears, but are there any other considerations here? I
> realize there may be scoping issues as well.
> 

def foo(input):
    import a_module

    a_module.do_things


if foo is never called a_module is never imported.  So if you could place
potentially unused modules inside functions this helps.  But this is also a
matter of style.





More information about the Python-list mailing list