Place of application for import

I have noticed many times that the mod mod import statement can be placed tightly before calling mod.something (). Although I noticed that usually developers put an import statement at the beginning of the source file. Is there a good reason for this?

I often use only a few functions from a certain module in a specific place. It seems prettier to me to explicitly position the import statement before calling the function.

eg.

# middle of the source file
import mod
mod.something()

What would you recommend and why?

+5
source share
2 answers

, / , - : , , , . , .

+6

, .

PEP , . , , , .

- , ( ), , - . , . -, , .

+5

All Articles