Path: csiph.com!usenet.pasdenom.info!gegeweb.org!newsfeed.kamp.net!newsfeed.kamp.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!194.109.133.85.MISMATCH!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: 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; 'argument': 0.04; "'.'": 0.09; 'hierarchical': 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; 'url:github': 0.09; '"this': 0.13; 'dotted': 0.16; 'iterating': 0.16; 'message- id:@dough.gmane.org': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'recipe': 0.16; 'subject:exists': 0.16; 'wrote:': 0.17; 'thanks,': 0.18; 'solution.': 0.18; 'load': 0.19; 'module': 0.19; 'do.': 0.21; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; '(as': 0.27; 'header:X-Complaints-To:1': 0.28; 'probably': 0.29; 'function': 0.30; 'url:python': 0.32; 'docs': 0.33; 'handle': 0.33; 'to:addr:python-list': 0.33; 'thanks': 0.34; 'fastest': 0.35; 'path': 0.35; 'pm,': 0.35; 'received:org': 0.36; 'but': 0.36; 'url:org': 0.36; 'url:library': 0.36; "didn't": 0.36; 'subject: (': 0.36; 'possible': 0.37; 'itself': 0.37; 'does': 0.37; 'subject:: ': 0.38; 'url:docs': 0.38; 'to:addr:python.org': 0.39; 'apply': 0.39; 'header:Received:5': 0.40; 'containing': 0.61; 'say:': 0.84; 'subject:find': 0.84; 'url:imp': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Gelonida N Subject: Re: find out whether a module exists (without importing it) Date: Tue, 07 Aug 2012 00:40:49 +0200 References: <062c08b7-a1d8-4858-b123-9a812804af0f@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: unicorn.dungeon.de User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120714 Thunderbird/14.0 In-Reply-To: <062c08b7-a1d8-4858-b123-9a812804af0f@googlegroups.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 24 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1344292871 news.xs4all.nl 6954 [2001:888:2000:d::a6]:59886 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:26666 On 08/06/2012 11:58 PM, Miki Tebeka wrote: >> imp.find_module(), but >> it didn't find any module name containing a '.' > The docs (http://docs.python.org/library/imp.html#imp.find_module) clearly say: > > "This function does not handle hierarchical module names(names > containing dots). Thanks, Well this explains. > In order to find P.M, that is, submodule M of package P, use find_module() and load_module() to find and load package P, and then use find_module() with the path argument set to P.__path__. When P itself has a dotted name, apply this recipe recursively." > > See https://gist.github.com/3278829 for possible implementation. > Using imp and then iterating (as you suggested) is probably the fastest solution. This is what I will do. Thanks again.