[Tutor] import errors

Emile van Sebille emile at fenx.com
Wed Aug 11 18:06:19 CEST 2010


On 8/11/2010 8:48 AM Pete said...
> Hi,
>
> A common line I've seen in Python code I come across is:
>
> #!/usr/bin/python
> import os
> import sys
> import errors
<snip>
> ... 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?

Importing looks in directories in sequence as held in sys.path

Python 2.4.3 (#1, Sep  3 2009, 15:37:12)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> import sys
 >>> for ii in sys.path: ii
...
''
'/usr/lib/python24.zip'
'/usr/lib/python2.4'
'/usr/lib/python2.4/plat-linux2'
'/usr/lib/python2.4/lib-tk'
'/usr/lib/python2.4/lib-dynload'
'/usr/lib/python2.4/site-packages'
'/usr/lib/python2.4/site-packages/Numeric'
'/usr/lib/python2.4/site-packages/gtk-2.0'


HTH,

Emile



More information about the Tutor mailing list