find out whether a module exists (without importing it)
Ramchandra Apte
maniandram01 at gmail.com
Tue Aug 7 08:40:18 EDT 2012
You are correct.
On 7 August 2012 14:38, Chris Angelico <rosuav at gmail.com> wrote:
> On Tue, Aug 7, 2012 at 6:00 PM, Gelonida N <gelonida at 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
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20120807/1e16acbc/attachment.html>
More information about the Python-list
mailing list