Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #26694
| References | <jvpaid$9ia$1@dough.gmane.org> <20120807064331.GA31774@terra.cms.at> <5020CB10.2020608@gmail.com> |
|---|---|
| Date | 2012-08-07 19:08 +1000 |
| Subject | Re: find out whether a module exists (without importing it) |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3047.1344330491.4697.python-list@python.org> (permalink) |
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
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: find out whether a module exists (without importing it) Chris Angelico <rosuav@gmail.com> - 2012-08-07 19:08 +1000
csiph-web