Imagine I have a script, let’s say my_tools.py that I import as a module. But my_tools.py is saved twice: at C:\Python27\Lib
and at the same directory from where the script is run that does the import.
Can I change the order where python looks for my_tools.py first? That is, to check first if it exists at C:\Python27\Lib and if so, do the import?
You can manipulate
sys.pathas much as you want… If you wanted to move the current directory to be scanned last, then just dosys.path[1:] + sys.path[:1]. Otherwise, if you want to get into the nitty gritty then the imp module can be used to customise until your hearts content – there’s an example on that page, and one at http://blog.dowski.com/2008/07/31/customizing-the-python-import-system/