While it is valid to use from module import *
at module level it
is usually a bad idea. For one, this loses an important property Python
otherwise has -- you can know where each toplevel name is defined by
a simple "search" function in your favourite editor. You also open yourself
to trouble in the future, if some module grows additional functions or
classes.
One of the most awful question asked on the newsgroup is why this code:
f = open("www") f.read()
does not work. Of course, it works just fine (assuming you have a file
called "www".) But it does not work if somewhere in the module, the
statement from os import *
is present. The os module
has a function called open() which returns an integer. While
it is very useful, shadowing builtins is one of its least useful properties.
Remember, you can never know for sure what names a module exports, so either
take what you need -- from module import name1, name2
, or keep them in
the module and access on a per-need basis --
import module;print module.name
.