imports after function definitions?

Robert Dickinson rdickins at usaor.net
Fri Aug 29 14:46:28 EDT 2003


The only restriction is that if you want to reference some imported thing at
the module level, then the import has to precede the use:

import x
class cls(x.cls1):
   pass

Other than that I don't know of any reasons (other than readability, which
can be interpreted to advantage either way).

-- Rob --

"Hallvard B Furuseth" <h.b.furuseth(nospam)@usit.uio(nospam).no> wrote in
message news:HBF.20030828usgy at bombur.uio.no...
> Is there any reason not to structure my program like this?
>
>    def ...
>    def ...
>    var = ...
>    var = ...
>    import ...
>    import ...
>    main_function()
>
> E.g. does it compile to slower code, or does it confuse PyChecker or
> something, if I put the imports after the functions that use them?
>
> --
> Hallvard






More information about the Python-list mailing list