When I'm rewriting code (cutting and pasting pieces from earlier
modules), is there a quick way to determine if I have imported all the
necessary modules? I am used to working in Java, where the compiler
will tell you if you haven't imported everything, and also Eclipse,
which has the handy "organize imports" feature. This is not the case in
Python, since it's not compiled, of course, and also running it might
not insure you've got all the imports, unless you go through every
possible usage scenario -- which in some cases is quite a few, and
could take a long time.
So what I'm looking for is a command, like "check dependencies" or
something, which will list all the modules needed for a source module
to run. 6 1154
mwt wrote: When I'm rewriting code (cutting and pasting pieces from earlier modules), is there a quick way to determine if I have imported all the necessary modules? I am used to working in Java, where the compiler will tell you if you haven't imported everything, and also Eclipse, which has the handy "organize imports" feature. This is not the case in Python, since it's not compiled, of course, and also running it might not insure you've got all the imports, unless you go through every possible usage scenario -- which in some cases is quite a few, and could take a long time.
So what I'm looking for is a command, like "check dependencies" or something, which will list all the modules needed for a source module to run.
If you are an accomplished Eclipse user (I'm not), you should look at
the Python plug-in for Eclipse.
Remember that Python is so dynamic that you can build dependencies
during program execution and import them on-the-fly. So a dependency
checker would always be incomplete. You always need to write unit
tests.
-Larry Bates
On 22/04/2006 8:18 AM, mwt wrote: When I'm rewriting code (cutting and pasting pieces from earlier modules)
Instead of propagating multiple copies of source code, consider
refactoring those modules so that top-level functions and classes can be
used in other modules.
is there a quick way to determine if I have imported all the necessary modules? I am used to working in Java, where the compiler will tell you if you haven't imported everything,
That's a clever design. It would be even better if it just shut up and
did the imports for you :-)
and also Eclipse, which has the handy "organize imports" feature. This is not the case in Python, since it's not compiled, of course, and also running it might not insure you've got all the imports, unless you go through every possible usage scenario -- which in some cases is quite a few, and could take a long time.
This is called "testing". Yes, it could take a long time. So what I'm looking for is a command, like "check dependencies" or something, which will list all the modules needed for a source module to run.
Consider pychecker and pylint. I haven't tried pylint, but pychecker
does what you want and a whole lot more:
C:\junk>type miss_import.py
# need to import re, but forgot
def my_isdigit(s):
return bool(re.match(r "\d+", s))
C:\junk>pycheck er miss_import
C:\junk>c:\pyth on24\python.exe
c:\python24\Lib \site-packages\pychec ker\checker.py miss_import
Processing miss_import...
Warnings...
miss_import.py: 3: No global (re) found
C:\junk>
John Machin wrote: This is called "testing". Yes, it could take a long time.
Thanks for the clarification. ;) Actually, I've done hellish amounts
of testing on these code pieces, which is why I don't want to have to
do it all over again just to check the imports. Consider pychecker and pylint. I haven't tried pylint, but pychecker does what you want and a whole lot more:
C:\junk>type miss_import.py # need to import re, but forgot def my_isdigit(s): return bool(re.match(r "\d+", s))
C:\junk>pycheck er miss_import
C:\junk>c:\pyth on24\python.exe c:\python24\Lib \site-packages\pychec ker\checker.py miss_import Processing miss_import...
Warnings...
miss_import.py: 3: No global (re) found
C:\junk>
That sounds really useful. I'll check it out. Thanks!
Wow! Just ran pychecker on a couple of modules. I'm blown away by how
much information I'm getting. Thanks again!
Wow! Just ran pychecker on a couple of modules. I'm blown away by how
much information I'm getting. Thanks again!
Larry Bates wrote: Remember that Python is so dynamic that you can build dependencies during program execution and import them on-the-fly. So a dependency checker would always be incomplete. You always need to write unit tests.
The Pychecker will usually see also missing on-the-fly imports and most
of that like.
You'd need to do tricky exec stuff to trick him - and even then he can
warn for smelling style of code.
You'd have to add upon warnings a #$pycheck_no to all such smelling
lines in order to confirm, that you really know what you are doing.
To my experience you'd usually not get the written tests dense enough
(at reasonable costs) to look into all branches of execution flow.
All 5 things are needed for efficiency :
(frequency of application decreasing the list down)
* auto-postmortem debugging (dev) ( auto-postmortem report (dist))
* running written tests
* code checks
* walking major execution branches by manual tests
* beta cycling
-robert This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Y2KYZFR1 |
last post by:
I have searched and only found references to using ODBC or some
ancient posts about some ancient sybase library under linux, neither
of which meets my critiera.
I need something that will cross platform without any of these
dependancies?
Does it exist?
|
by: Larry |
last post by:
I have a Perl script using DBD::DB2, that runs during system startup on
a Solaris system. The script is working fine during startup on many
machines, except on one machine it fails complaining about a missing
".so" file, with Perl flagging the "use DBD::DB2" line. (I don't have
the exact message since I'm heard about it from a remote sysadmin who
only saw it scroll by on the console). However, if I login as root on
that machine and run...
|
by: Chris Bruner |
last post by:
I've got a program that is successfully selling, that I would like to move
from MFC to C#. My method of deployment is to copy the program and data files
to an SDCard using the main PC program. That is, the user puts an sd card in,
and updates the drive that the card is. Then when the user puts the card in
their pocketPC they run the program from the SDCard.
This same method is used for palms as well, and in actual fact both the palm
and...
|
by: kj |
last post by:
I'm a Python noob, and haven't yet figured out my way around the
Python documentation.
For example, suppose I learn about some great module foo.bar.baz,
and when I run the python interpreter and type "import foo.bar.baz",
lo and behold, it is already installed on our system, which means
that (knowing that our system is pretty bare-bones as far as python
goes) most likely foo.bar.baz is part of the standard python
installation.
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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,...
|
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...
|
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...
|
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...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |