Improvement to imports, what is a better way ?

Greg Ewing greg.ewing at canterbury.ac.nz
Wed Jan 18 17:29:54 EST 2023


On 19/01/23 10:40 am, Dan Kolis wrote:
> I guess I don't full understand what bothers me about the repetition of the imports so much.

It's doubtful that every module uses every one of those imports.
It looks like someone had a standard block of imports that they
blindly pasted at the top of every file, to avoid having to think
about which ones were actually needed.

If you're looking for advice, I would suggest:

* Only import what you use in a particular file (this doesn't
have much effect on efficiency, but there's less clutter for
the reader.)

* Only use short names for modules that are *very* frequently
referenced. Use full unabbreviated names for everything else.

* Don't 'import foo as foo', just 'import foo'.

* Don't try to line the code up in columns, it doesn't really
help readability IMO.

-- 
Greg


More information about the Python-list mailing list