What are the “best practices” for using import in a module?
In general, don’t use from modulename import *. Doing so clutters the importer’s namespace. Some people avoid this idiom even with the few modules that were designed to be imported in this manner. Modules designed in this manner include Tkinter, and threading. Import modules at the top of a file. Doing so makes it clear what other modules your code requires and avoids questions of whether the module name is in scope. Using one import per line makes it easy to add and delete module imports, but using multiple imports per line uses less screen space. It’s good practice if you import modules in the following order: • standard library modules — e.g. sys, os, getopt, re) • third-party library modules (anything installed in Python’s site-packages directory) — e.g. mx.DateTime, ZODB, PIL.Image, etc. • locally-developed modules Never use relative package imports. If you’re writing code that’s in the package.sub.m1 module and want to import package.sub.m2, do not just write import m2, even th