Importing modules through directory shortcuts on Windows

Brian Quinlan brian at sweetapp.com
Wed Apr 26 09:36:07 EDT 2006


Recently, I became responsible for maintaining some Python code, which 
was organized as follows:

user/pylib
      ui
      ...
project2/pylib
          ui
          ...
project3/pylib
          ui
          ...
python-packages/user => /user/pylib
                 project2 => /project2/pylib
                 project3 => /project3/pylib

The idea is that "python-packages" is added to sys.path and then every 
project can import the library package from every other project. NOTE: I 
think that this structure is crazy but I'm just the poor maintenance 
programmer.

Anyway, the problem is that Windows does not have a symlink facility to 
accommodate this (AFAIK) and the Python import mechanism does not 
resolve shortcuts.

Therefore, I wrote a very simple import hook to get around that problem. 
  If you are interested, the code is here:
http://www.sweetapp.com/shortcut/shortcutimporter.py

BTW, does anyone else think that this functionality should be part of 
core Python?

Cheers,
Brian



More information about the Python-list mailing list