Good or bad practice in Python: import in the middle of a file [duplicate]

PEP 8 authoritatively states:

Imports are always put at the top of
the file, just after any module
comments and docstrings, and before module globals and constants.

PEP 8 should be the basis of any “in-house” style guide, since it summarizes what the core Python team has found to be the most effective style, overall (and with individual dissent of course, as on any other language, but consensus and the BDFL agree on PEP 8).

Leave a Comment