How to test if a module exists?

2010-11-06 Thread Jon Dufresne
Hi, My python program has an extension system where the extension can have a optional magic python modules. Meaning if the extension module exists, the program will use it and if not, it will continue without the module. So my program tests if a module exists, if so use it, otherwise continue. Thi

Re: How to test if a module exists?

2010-11-06 Thread Jon Dufresne
On Sat, Nov 6, 2010 at 11:35 AM, Chris Rebert wrote: > Here's what I came up with: > > try: >     import extension_magic_module > except ImportError as err: >    if err.message != "No module named extension_magic_module": >        raise err > else: >    handle_extension_magic_module() > It seems

Re: How to test if a module exists?

2010-11-06 Thread Jon Dufresne
On Sat, Nov 6, 2010 at 1:52 PM, Roy Smith wrote: > > import sys > try: >    import xx > except ImportError: >    tb = sys.exc_traceback >    while tb: >        print tb >        tb = tb.tb_next > I went ahead and implemented this and it now works. I even uncovered a bug I wasn't previously seeing

Re: How to test if a module exists?

2010-11-09 Thread Jon Dufresne
On Tue, Nov 9, 2010 at 4:30 AM, Roy Smith wrote: > In article , >  Lawrence D'Oliveiro wrote: > >> In message , Roy Smith wrote: >> >> > On the other hand, if your module's bug is that it in turn imports some >> > other module, which doesn't exist, you'll also get an ImportError. >> >> Does it re

Re: How to test if a module exists?

2010-11-09 Thread Jon Dufresne
On Mon, Nov 8, 2010 at 11:35 PM, Lawrence D'Oliveiro wrote: > In message , Roy Smith wrote: > >> On the other hand, if your module's bug is that it in turn imports some >> other module, which doesn't exist, you'll also get an ImportError. > > Does it really matter? Either way, the module is unusab

Re: How to test if a module exists?

2010-11-10 Thread Jon Dufresne
On Wed, Nov 10, 2010 at 1:50 AM, Lawrence D'Oliveiro wrote: > In message , Jon > Dufresne wrote: > >> On Mon, Nov 8, 2010 at 11:35 PM, Lawrence D'Oliveiro ... > > I see that you published my unobfuscated e-mail address on USENET for all to > see. I obfuscated it