I've been using python to do computations for my research. In an effort to clean up my terrible code, I've been reading Code Like a Pythonista: Idiomatic Python by David Goodger.
In this article, Goodger advises against "wild-card" imports of the form
from module import *
Use a tool like
pyflakes (which you should use anyway) to note which names in your code become undefined after you replace
from module import * with
import module. Once you've positively identified every instance of a name imported from
module, you can assess whether to
import module as mand
m.xif the module name is long.
moduleinto the module namespace with
from module import x, y, z
The above three are not mutually exclusive; as an extreme example, you can use all three in the same module:
import really.long.module.name import really.long.module.name as rlmn from really.long.module.name import obvious_name really.long.module.name.foo() # full module name rlmn.bar() # module alias obvious_name() # imported name
all in the same code. (I don't recommend using all three in the same module. Stick with either the full module name or the alias throughout a single module, but there is no harm importing common, obvious names directly and using the fully qualified name for more obscure module attributes.)