473,385 Members | 2,069 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

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
1 936
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: C. Barnes | last post by:
OK, here's the setup: package/ __init__.py X.py python/lib/ X.py Now inside package, we want to import the copy
4
by: Steve Holden | last post by:
I'm trying to load module code from a database, which stores for each module its full name, code, load date and a Boolean indicating whether it's a package or not. The following simple program:...
0
by: Mark English | last post by:
Basic problem: If there is a C-extension module in a package and it tries to import another python module in the same package without using the fully qualified path, the import fails. Config:...
8
by: Philippe C. Martin | last post by:
Hi, I'm getting pretty desperate here: The code below crashes on the last line (but works from a shell). The class 'BC' exists and the loop on self.__BC_EXEC_LIST passes fine. It's got to...
21
by: J. Smith | last post by:
I know about RAII and BS's response to previous requests, but I'd really love to see 'finally' available in C++ exception handling. Yes, we can live without 'finally' but it means a bit more...
7
by: Ron Adam | last post by:
from __future__ import absolute_import Is there a way to check if this is working? I get the same results with or without it. Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) on win 32 ...
2
by: patrimith | last post by:
Hi List, I am used to the following with Java: import some.package.MyClass; name = MyClass.class.getName(); The value for name will be "some.package.MyClass". For Python, I find:
0
by: Patrick Bouffard | last post by:
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...
12
lifeisgreat20009
by: lifeisgreat20009 | last post by:
I am a newbie to Struts and JSP...I have been working on the code below for 5 hours now..I googled a lot but couldn't get much help so finally I am here.. Hoping of getting my problem solved. Please...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.