[Tutor] import errors

Pete pkoek11 at xs4all.nl
Wed Aug 11 17:48:52 CEST 2010


Hi,

A common line I've seen in Python code I come across is:

#!/usr/bin/python
import os
import sys
import errors

I was wondering about the line that says, "import errors". I understand what it's for, but what I don't get is how Python knows which 'errors.py' to import.

On my laptop:

macbook:bin han$ locate errors.py | grep -E 'py$'
/Library/Frameworks/Mono.framework/Versions/2.4.2.1/lib/IPCE/Lib/_codecs_errors.py
/Library/Frameworks/Mono.framework/Versions/2.4.2.1/lib/IPCE/Lib/fepy/codecs_errors.py
/Library/Python/2.6/site-packages/Skype4Py/errors.py
/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/distutils/errors.py
/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/plat-mac/macerrors.py
/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/distutils/errors.py
/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/email/errors.py
/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/plat-mac/macerrors.py
/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/distutils/errors.py
/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/email/errors.py
/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac/macerrors.py

... so there seem to be more than one 'errors.py' - one for the email module, one for Skype4Py, etc.

How does the interpreter know which one to import?

Thanks for all your time, btw - I'm learning a lot lurking on this list and greatly appreciate all the people offering help and advice.

cheers,

Pete


More information about the Tutor mailing list