try except ImportError failing to catch error!

Ben Gerblich benji_75 at
Wed Sep 18 05:31:05 EDT 2002

I am importing all module files in the CWD. This part works fine.

I want to add the functionality to catch the error if there is a
typo in the imported module file. The following does not catch
the error!

    self.userDefs[file[:-3]]['class'] = __import__(file[:-3])
except ImportError, e:
    print 'cant do it', e

I still get the runtime error:

Traceback (most recent call last):
  File "./", line 8, in ?
    application = testApp()
  File "/usr/lib/python2.1/site-packages/wxPython/", line 1581, in 
__init__    _wxStart(self.OnInit)
  File "./", line 3444, in OnInit
    self.frame = MainFrame(None)
  File "./", line 2836, in __init__
    exec code
  File "<string>", line 1, in ?
  File "./", line 33, in __init__
    self.line(5, 60, 15, 60,999)
TypeError: line() takes exactly 5 arguments (6 given)

I expect this error! as the '999' should not be there.
Why does not the 'cant to it' line print instead?

And is there a way for my handler routine to return the line-number of the 
imported module file that caused the error?

Im using:
Red Hat Linux 7.1

MSN Photos is the easiest way to share and print your photos:

More information about the Python-list mailing list