Tuesday, July 31, 2012

Python: Paths, packages and directory organization

Adding a path (/a) to a .pth file placed in a directory already on python's search path will add /a to the search path.

If we have a subdirectory b under a (/a/b) modules in thsi subdirectory will not be included in the path. A second line /a/b needs to be included in the .pth file

If we add a file __init__.py to b/ (the file can be empty) then python treats the structure as part of a package and we can then do (assuming mod.py is a module in /a/b)

import b.mod

No comments:

Post a Comment