no module named exceptions?

Gary Herron gherron at digipen.edu
Thu Apr 1 16:10:34 EDT 2010


Joaquin Abian wrote:
> In python 3.1,
>
>   
>>>> import exceptions
>>>>         
> Traceback (most recent call last):
>   File "<pyshell#6>", line 1, in <module>
>     import exceptions
> ImportError: No module named exceptions
>
> in 2.6 no exception is raised
> It should be the same in 3.1, isnt it?
>
> Joaquin
>   

In 2.x, the exceptions module was imported automatically, so there was 
never a need to explicitly import it.
For example:
Python 2.6.4 (r264:75706, Dec  7 2009, 18:45:15)
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> print ImportError
<type 'exceptions.ImportError'>


In Python 3.x, it appears the same effect is achieved by putting the 
Exceptions in the builtin module
For example:
Python 3.1.1+ (r311:74480, Nov  2 2009, 14:49:22)
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> print(ImportError)
<class 'ImportError'>

And another example:
 >>> import builtins
 >>> print(builtins.ImportError)
<class 'ImportError'>


-- 
Gary Herron, PhD.
Department of Computer Science
DigiPen Institute of Technology
(425) 895-4418




More information about the Python-list mailing list