Determining which things in 'from package import *' are actually used

Patrick Bouffard patrick.m.bouffard at gmail.com
Tue Jun 10 16:49:19 EDT 2008


On Jun 10, 3:03 pm, Robert Kern <robert.k... at gmail.com> wrote:
> Patrick Bouffard wrote:
> > I have a fairly large library of Python code, where 'from package import *' is
> > used rather liberally, and it's not uncommon for more than one of these to
> > appear in any given module. What I'd like to be able to do is to clean my code
> > up a bit and turn each of the 'from package import *' statements into 'from
> > package import thing_1, thing_2, ..., thing_n', where only thing_i's that are
> > actually _used_ in the module are imported. In this way I hope to make my code a
> > bit more understandable by future civilizations. :) (it needs all the help it
> > can get!)
>
> > Does anyone know of a package/recipe/whatever that does something like this
> > automatically, even in limited cases? Ideally it should be accomplished only by
> > looking at the source, or at most, importing the module.
>
> I don't know of any automatic tools. I usually comment out those import
> statements and use pyflakes to show me the undefined names.
>
> --
> Robert Kern
>
> "I have come to believe that the whole world is an enigma, a harmless enigma
>   that is made terrible by our own mad attempt to interpret it as though it had
>   an underlying truth."
>    -- Umberto Eco

Thanks, I didn't know about pyflakes. What you describe sounds like a
great place to start, I'll give it a go.

-Pat



More information about the Python-list mailing list