Import * considered harmful
This is old news, but it needs to be said again.
To use an example from a day in my coding life, yesterday to be exact, here is an example of how things go pear-shaped when you use import * without fully considering the future ramifications of your laziness. For this example we will use sqlalchemy and reportlab which both implements a String class.
""" util.py """ from sqlalchemy import *
""" strangeness.py """ from reportlab.graphics.shapes import String from util import * print String.__module__
Now strangeness.py spits out sqlalchemy.types rather than the expected reportlab.graphics.shapes. Naturally it all makes perfect sense once you've inspected modules util, sqlalchemy and sqlalchemy.types and finally find the String class, but I suspect it is glaringly obvious that all this could have been avoided if you kept your name space clean to start with. Importing an entire module might give you more than you bargained for, especially if the module you're importing does some gratuitous imports of its own.
This is perhaps a good time to rant a little about the code examples used in documentation. An example is usually not long nor complex, and does not use that many classes to illustrate the point. Using a gratuitous import * in an example should, in my opinion, be avoided, for this is often repeated in the final code and leads to weird errors.
On the other hand I must point out that there are good uses for the import * pattern. This is typically used in plone products to import configuration variables:
from config import *
The point I want to make is that you should use it sparingly.






