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

Discussion in 'Python' started by Michael Poeltl, Aug 7, 2012.

  1. in my opinion, "without importing it" makes it unnecessarily complicated.
    You just want to know it module xyz exists, or better said can be found
    (sys.path).

    why not try - except[ - else ]

    try:
    import mymodule
    except ImportError:
    # NOW YOU KNOW it does not exist
    #+ and you may react properly
    ??
    * Gelonida N <> [2012-08-06 22:49]:
    > 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.
    >
    >
    > --
    > http://mail.python.org/mailman/listinfo/python-list


    --
    Michael Poeltl
    Computational Materials Physics voice: +43-1-4277-51409
    Univ. Wien, Sensengasse 8/12 fax: +43-1-4277-9514 (or 9513)
    A-1090 Wien, AUSTRIA cmp.mpi.univie.ac.at
    -------------------------------------------------------------------------------
    ubuntu-11.10 | vim-7.3 | python-3.2.2 | mutt-1.5.21 | elinks-0.12
    -------------------------------------------------------------------------------
     
    Michael Poeltl, Aug 7, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. plb
    Replies:
    2
    Views:
    358
  2. Gelonida N
    Replies:
    3
    Views:
    154
    Gelonida N
    Aug 6, 2012
  3. Gelonida N
    Replies:
    0
    Views:
    150
    Gelonida N
    Aug 7, 2012
  4. Peter Otten
    Replies:
    0
    Views:
    141
    Peter Otten
    Aug 7, 2012
  5. Chris Angelico
    Replies:
    0
    Views:
    134
    Chris Angelico
    Aug 7, 2012
Loading...

Share This Page