473,830 Members | 2,022 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 952
On Jun 10, 3:03*pm, Robert Kern <robert.k...@gm ail.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
1025
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
3591
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: import dbimp, sys if __name__ == "__main__": dbimp.install()
0
1378
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: Python 2.4 on Windows 2000 For example: mypackage contains:
8
1533
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 be something really stupid but I've been looking at it too long I guess.
21
1462
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 typing (more classes) for simple scenarios (like calling LeaveCriticalSection() before a function returns). It would also make porting other languages to C++ a bit more simple. Another thing I'd like to see is a 'reentrant' keyword that can be...
7
20582
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 _Ron
2
8216
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
740
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 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...
12
78040
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 give me some idea where I am going wrong ?? I just want to retrieve data from my emp_mstr table and display it using my JSP file... The table emp_mstr is as follows :- CREATE TABLE EMP_MSTR( EMP_NO VARCHAR(10) PRIMARY KEY, PASSWORD...
0
9642
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10774
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10491
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10206
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9315
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7746
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5780
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3959
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3076
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.