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


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

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

Started byChris Angelico <rosuav@gmail.com>
First post2012-08-07 19:08 +1000
Last post2012-08-07 19:08 +1000
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) Chris Angelico <rosuav@gmail.com> - 2012-08-07 19:08 +1000

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

FromChris Angelico <rosuav@gmail.com>
Date2012-08-07 19:08 +1000
SubjectRe: find out whether a module exists (without importing it)
Message-ID<mailman.3047.1344330491.4697.python-list@python.org>
On Tue, Aug 7, 2012 at 6:00 PM, Gelonida N <gelonida@gmail.com> wrote:
> modulename = 'my.module'
> cmd = 'import %s as amodule'
> try:
>     exec(cmd)
>     print "imported successfully"

Someone will doubtless correct me if I'm wrong, but I think you can
avoid exec here with:

amodule=__import__(modulename)

ChrisA

[toc] | [standalone]


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


csiph-web