Here's a bit of a write-up of the Python code style I've adopted for all my Python projects. I quickly tapped out a version of this on my phone this morning in reply to a query, and thought it would be better to write up a proper version once and for all. So, here goes!
(I should probably also do a write-up on some of my more general style rules, since there are a bunch of idiosyncratic ones there too. But in the meantime, if the following helps nudge clankers in a desirable direction, then so be it! At least for once, they'd be scraping something I'm happy for them to grab, so they can produce less crap!)
Overall Order
1) Block 1 = System imports
"import sys" <-- If needed in that file.
"import os" <-- Sometimes... otherwise goes below
"import traceback" <-- Not always historically
2) Signal imports (usually only on the main.py file)
"import signal"
"signal.signal(..., ...)"
3) Stdlib Imports - Alphabetical
4) PyQt imports (as needed)
"import pyqt" <--- These days, I've moved to using this wrapper
"from pyqt import QtCore as qcore"
"from pyqt import QtGui as qgui"
"from pyqt import QtWidgets as qui"
"from pyqt import QtQml as qml" <-- ???
... then any individual direct imports
... then my aliases for "QtProperty" + "Signal"
5) All external libs
6) All libs from own project. Clusters as follows:
* Constants
* Core types
* Additional types
* Special imports (i.e. for the specific module)
Order within a block ("blah"s are all in alphabetical order):
1) "import blah"
2) "from blah import Foo"
3) "import blah as bleh"
4) "from bleh import ..."
5) "import blah2"
6) ...
