Search This Blog

Sunday, March 16, 2014

import search path

Python looks are several directories when you try to import a module. It mainly searched the directories defined in sys.path. This is a list and you can see it as follows:

>>> import sys
>>> sys.path
['', 'C:\\Python33\\Lib\\idlelib', 'C:\\Python33\\lib\\site-packages\\selenium-2.40.0-py3.3.egg', 'C:\\Windows\\system32\\', 'C:\\Python33\\DLLs', 'C:\\Python33\\lib', 'C:\\Python33', 'C:\\Python33\\lib\\site-packages']

If you want it to see in other directories, you can make it search it by using the sys.path.insert( 0, new_path ). This is very useful, if you want to import your own custom module.

No comments:

Post a Comment