== A Python wish: an easy, widely supported way to turn a path into a module Years ago I wrote [[a grumpy entry about Django 1.4's restructured directory layout ../programming/BadProjectLayout]] and mentioned that I was not reorganizing [[our Django web app DjangoORMDesignPuzzleII]] to match. In the time since then, it has become completely obvious that grimly sticking to my guns here is not a viable answer over the long term; sooner or later, ideally sooner, I need to restructure the app into what is now the proper Django directory layout. One of the reasons that I objected to this (and still do) is [[the problem of how you make a directory into a module EverythingModuleProblem]]; simply adding the parent directory to _$PYTHONPATH_ has several limitations. Which is where my wish comes in. What I wish for is a simple and widely supported way to say 'directory _/some/thing/here/fred-1_ is the module _fred_'. This should be supported on the Python command line, in things like ((mod_wsgi)), and in Python code itself (so you could write code that programmatically added modules this way, similar to how you can extend _sys.path_ in code). The named module is not imported immediately, but if later code does '_import fred_' (or any of its variants) it will be loaded from _/some/thing/here/fred-1_ (assuming that there is no other _fred_ module found earlier on the import path). All of the usual things work from there, such as importing submodules ('_import fred.bob_') and so on. The _fred-1_ directory would have a ((__init__.py)) and so on as normal. (Note that it is not necessary for the final directory name to be the same as the module name. Here we have a directory being _fred-1_ but the module is _fred_.) Given [[PEP 302 http://legacy.python.org/dev/peps/pep-0302/]], I think it's probably possible to implement this in Python code. However, both PEP 302 and the entire current Python import process make my head hurt so I'm not sure (and there are probably differences between Python 2 and Python 3 here). (I wrote [[some notes to myself about Python packaging PythonPackagingNotes]] a while back, which is partly relevant to this quest. I don't think _.egg_ and _.zip_ files let me do what I want here, even if I was willing to pack things up in _.zip_s, since I believe their filenames are bound to the package/module name.)