By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,676 Members | 2,262 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,676 IT Pros & Developers. It's quick & easy.

Re: Determining which things in 'from package import *' are actuallyused

P: n/a
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

Jun 27 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Jun 10, 3:03*pm, Robert Kern <robert.k...@gmail.comwrote:
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 thoughit 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
Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.