views:

217

answers:

1

I currently do this:

PYTHONPATH=/home/$USER:/home/$USER/respository:/home/$USER/repository/python-stuff

How can I make it so that the PYTHONPATH can include everything subdirectory?

PYTHONPATH = /home/$USER/....and-all-subdirectories
+5  A: 

It's generally a bad idea to have on sys.path two paths one of which is the parent of the other -- assuming the sub-directory one contains an __init__.py file to mark it as a package, of course. If only the parent directory is in the path (and $PYTHONPATH is part of what sys.path is initialized with), modules in the subdirectory can be imported from the package, i.e., through just one filesystem path, avoiding the risk of a single module being imported under many distinct guises.

So why don't you just put __init__.py files in all subdirectories that need it, and use package imports?

While I think your request is a bad idea, it's certainly doable -- the Unix find command can easily list all subdirectories of a directory, one per line (find . -type d), and you can easily glue the lines together e.g. by piping find's output to tr '\n' :.

Alex Martelli
Thanks Alex Martelli! You need to write more books.
TIMEX
Yes I do, but finding the time and energy is hard;-).
Alex Martelli