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


Groups > comp.lang.python > #26693

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

Path csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!news2.euro.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'correspond': 0.07; "'.'": 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:module': 0.09; 'toplevel': 0.09; 'message- id:@dough.gmane.org': 0.16; 'received:80.91.229.3': 0.16; 'received:dip.t-dialin.net': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-dialin.net': 0.16; 'subject:exists': 0.16; 'sys.path': 0.16; 'wrote:': 0.17; 'directory.': 0.17; 'module': 0.19; 'import': 0.21; "i'd": 0.22; 'somewhere': 0.24; 'tried': 0.25; 'header:User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.28; 'actual': 0.28; 'closer': 0.29; 'performing': 0.30; 'located': 0.31; "skip:' 20": 0.32; 'could': 0.32; 'to:addr :python-list': 0.33; 'received:org': 0.36; 'but': 0.36; 'modules': 0.36; "didn't": 0.36; 'subject: (': 0.36; 'subject:: ': 0.38; 'possible.': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'think': 0.40; 'containing': 0.61; 'gelonida': 0.84; 'subject:find': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Peter Otten <__peter__@web.de>
Subject Re: find out whether a module exists (without importing it)
Date Tue, 07 Aug 2012 10:27:46 +0200
Organization None
References <jvpaid$9ia$1@dough.gmane.org>
Mime-Version 1.0
Content-Type text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding 7Bit
X-Gmane-NNTP-Posting-Host p508497e6.dip.t-dialin.net
User-Agent KNode/4.7.3
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3046.1344328071.4697.python-list@python.org> (permalink)
Lines 18
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1344328071 news.xs4all.nl 6895 [2001:888:2000:d::a6]:34404
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:26693

Show key headers only | View raw


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.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

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

csiph-web