How to add all subfolders a folder to PYTHONPATH

2

All of my Python module sources are in the folder /src/*:

/src/module1
/src/module2
    ...
/src/modules100

If I want to add all of these modules to my PYTHONPATH, I need to add them individually in my .bashrc by using the export command. Is it possible to add them by one command? (basically adding everything under the /src/* folder to my PYTHONPATH)

motam79

Posted 2017-10-16T17:59:08.840

Reputation: 300

Answers

0

You can find various options to do that over on Stack Overflow. One of the easiest:

PYTHONPATH="$(printf "%s:" /src/*/)"

Here, /src/*/ expands into all directories under /src/. printf then uses a colon (:) as separator character.

slhck

Posted 2017-10-16T17:59:08.840

Reputation: 182 472