Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: find out whether a module exists (without importing it)

Reply
Thread Tools

Re: find out whether a module exists (without importing it)

 
 
Peter Otten
Guest
Posts: n/a
 
      08-07-2012
Gelonida N wrote:

> Is this possible.
>
> let's say I'd like to know whether I could import the module
> 'mypackage.mymodule', meaning,
> whther this module is located somewhere in sys.path
>
> i tried to use
>
> imp.find_module(), but
> it didn't find any module name containing a '.'


You could look for the toplevel name and then look for modules in the
corresponding directory. This is not always reliable as a package may not
correspond to a directory (e. g.: os and os.path), but I don't think you can
get any closer without performing an actual import.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: find out whether a module exists (without importing it) Chris Angelico Python 0 08-07-2012 09:08 AM
Re: find out whether a module exists (without importing it) Gelonida N Python 0 08-07-2012 08:00 AM
Re: find out whether a module exists (without importing it) Michael Poeltl Python 0 08-07-2012 06:43 AM
find out whether a module exists (without importing it) Gelonida N Python 3 08-06-2012 10:40 PM
How to keep a module with the same name as a module it is importing from importing itself? plb Python 2 02-08-2005 03:14 PM



Advertisments