Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #26693 > unrolled thread

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

Started byPeter Otten <__peter__@web.de>
First post2012-08-07 10:27 +0200
Last post2012-08-07 10:27 +0200
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: find out whether a module exists (without importing it) Peter Otten <__peter__@web.de> - 2012-08-07 10:27 +0200

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

FromPeter Otten <__peter__@web.de>
Date2012-08-07 10:27 +0200
SubjectRe: find out whether a module exists (without importing it)
Message-ID<mailman.3046.1344328071.4697.python-list@python.org>
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.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web