473,387 Members | 1,502 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,387 software developers and data experts.

look for a module without import it

Hi list,
I have to know if a module are present on the system, but I don't want
to import it. Only know if it is present.
I think that a loop on the site-packages directory can do the work, but
is there another solution?

Thanks,
Michele
Jul 14 '06 #1
2 1085
Michele Petrazzo wrote:
I have to know if a module are present on the system, but I don't want
to import it. Only know if it is present.

I think that a loop on the site-packages directory can do the work, but
is there another solution?
more module.py
print "I'M MODULE!"
python
>>import imp
imp.find_module("os")
(<open file 'C:\python25\lib\os.py', mode 'U' at 0x00A7E2F0>, 'C:\\python25\\lib\\os.py', ('.py',
'U', 1))
>>imp.find_module("sys")
(None, 'sys', ('', '', 6))
>>imp.find_module("foobar")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named foobar
>>imp.find_module("module")
(<open file 'module.py', mode 'U' at 0x00A7E2F0>, 'module.py', ('.py', 'U', 1))
>>import module
I'M MODULE!

</F>

Jul 14 '06 #2
Fredrik Lundh wrote:
>more module.py
print "I'M MODULE!"
>python
>>>import imp imp.find_module("os")
It was!

Michele
Jul 14 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Sean | last post by:
Is there any way I could have the following work? First I would have a module define a function to do something like print some data. ----- module_name.py ----- def print_this(data):
4
by: Bo Peng | last post by:
Dear list, What I would like to do is something like: In myModule.py ( a wrapper module for different versions of the module), if lib == 'standard': from myModule_std import * elsif lib ==...
2
by: Reid Priedhorsky | last post by:
Dear group, I'd have a class defined in one module, which descends from another class defined in a different module. I'd like the superclass to be able to access objects defined in the first...
6
by: kimes | last post by:
I've just started digging into how python works.. I found that other mudules are clearly declared like one file per a module.. But the only os.path doesn't have their own file.. ye I know is...
3
by: Mudcat | last post by:
I have a directory structure that contains different modules that run depending on what the user selects. They are identical in name and structure, but what varies is the content of the functions....
10
by: Ben Finney | last post by:
Howdy all, Question: I have Python modules named without '.py' as the extension, and I'd like to be able to import them. How can I do that? Background: On Unix, I write programs intended to...
5
by: Johann C. Rocholl | last post by:
The following is my first attempt at adding a taint feature to Python to prevent os.system() from being called with untrusted input. What do you think of it? # taint.py - Emulate Perl's taint...
2
by: krishna.000.k | last post by:
file1.py ---------- a = 20 from abc import * print "Should this be printed when 'a' is alone imported from this module" file2.py ---------- from file1 import a
2
by: Kless | last post by:
How to check is a library/module is installed on the system? I use the next code but it's possivle that there is a best way. ------------------- try: import foo foo_loaded = True except...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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.