bug? context managers vs ImportErrors

Chris Withers chris at simplistix.co.uk
Thu Aug 19 17:58:30 CEST 2010

Hi All,

Am I right in thinking this is a bug:

class MyContextManager:

     def __enter__(self):

     def __exit__(self,t,e,tb):
         print type(t),t
         print type(e),e

with MyContextManager():
    import foo.bar.baz

...when executed, gives me:

<type 'type'> <type 'exceptions.ImportError'>
<type 'str'> No module named foo.bar.baz

Why is 'e' ending up as a string rather than the ImportError object?

This is with Python 2.6.5 if that makes a difference...


More information about the Python-list mailing list