May I know in a Python environment, which is compliant with PEP-8?
Imports before global variables:
import some_library
GLOBAL_VARIABLE = "something"
Or global variables before imports:
GLOBAL_VARIABLE = "something"
import some_library
May I know in a Python environment, which is compliant with PEP-8?
Imports before global variables:
import some_library
GLOBAL_VARIABLE = "something"
Or global variables before imports:
GLOBAL_VARIABLE = "something"
import some_library
PEP 8 says about imports:
Imports are always put at the top of the file, just after any module comments and docstrings, and before module globals and constants.
so this
import some_library
GLOBAL_VARIABLE = "something"
is PEP-8 compliant, and this
GLOBAL_VARIABLE = "something"
import some_library
is not.
The standard is for the imports to come before the global variables. There are several advantages to this:
As mentioned in some other comments, using globals is not really the best practice in Python. You can read more about this here.