First of all, yes I'm aware of PEP8 and the alphabetical method.
I do sort my imports first by the PEP8 recommendation:
- standard library imports
- related third party imports
- local application/library specific imports
But then, within each category, I like to sort by the length of the module name. Yes, it makes it look pretty, but then I find it arguably makes it easier to find a module than the alphabetical way.
Also, the shorter names tend to be the more basic, common modules (like
sys), so there's an additional organization layer in that way. You know the length of the name you're looking for, and the visual shape of the import list tells you very quickly where to look for names that long.
import os import sys import time import logging import argparse import subprocess import django import requests import webencodings import mymodule import localthing import supercustomstuff
Right now I mostly write for myself, and I don't work with a team. But I intend to in the future. So what I'm wondering is, does anyone else do this, does anyone else see the sense in it, or will everyone else think I'm nuts?
Edit: Separate subgroups in example, as suggested by Mark Ransom, in order not to distract from the core issue about the ordering.