Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #26657 > unrolled thread
| Started by | Gelonida N <gelonida@gmail.com> |
|---|---|
| First post | 2012-08-06 22:48 +0200 |
| Last post | 2012-08-07 00:40 +0200 |
| Articles | 4 — 2 participants |
Back to article view | Back to comp.lang.python
find out whether a module exists (without importing it) Gelonida N <gelonida@gmail.com> - 2012-08-06 22:48 +0200
Re: find out whether a module exists (without importing it) Miki Tebeka <miki.tebeka@gmail.com> - 2012-08-06 14:58 -0700
Re: find out whether a module exists (without importing it) Miki Tebeka <miki.tebeka@gmail.com> - 2012-08-06 14:58 -0700
Re: find out whether a module exists (without importing it) Gelonida N <gelonida@gmail.com> - 2012-08-07 00:40 +0200
| From | Gelonida N <gelonida@gmail.com> |
|---|---|
| Date | 2012-08-06 22:48 +0200 |
| Subject | find out whether a module exists (without importing it) |
| Message-ID | <mailman.3030.1344286110.4697.python-list@python.org> |
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 '.' Am I doing anything wrong? Is there another existing implementation, that helps. I could do this manually, but this is something I'd just like to do if necessary.
[toc] | [next] | [standalone]
| From | Miki Tebeka <miki.tebeka@gmail.com> |
|---|---|
| Date | 2012-08-06 14:58 -0700 |
| Message-ID | <mailman.3034.1344290308.4697.python-list@python.org> |
| In reply to | #26657 |
> 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). 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.
[toc] | [prev] | [next] | [standalone]
| From | Miki Tebeka <miki.tebeka@gmail.com> |
|---|---|
| Date | 2012-08-06 14:58 -0700 |
| Message-ID | <062c08b7-a1d8-4858-b123-9a812804af0f@googlegroups.com> |
| In reply to | #26657 |
> 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). 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.
[toc] | [prev] | [next] | [standalone]
| From | Gelonida N <gelonida@gmail.com> |
|---|---|
| Date | 2012-08-07 00:40 +0200 |
| Message-ID | <mailman.3036.1344292871.4697.python-list@python.org> |
| In reply to | #26665 |
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.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web