Reputation: 2243
There are only one or two modules which I need from the a folder which contains several other python modules. When I add the folder to my path, I effectively make all the modules in that folder available to me. But there are several outdated modules which I do not want. Is it possible to only make a certain subset of those modules available to me?
Upvotes: 1
Views: 145
Reputation: 50200
Create a new directory. For each module you want to import, add a symbolic link (ln -s
) pointing to the real module. Then add the new directory to your path, and you won't have to play games with your include order.
mkdir ./mymods
export PYTHONPATH="$PYTHONPATH":`pwd`/mymods
cd mymods
ln -s ../allmods/module1.py
ln -s ../allmods/module2.py
Upvotes: 1
Reputation: 63737
Reading your question I understand that
I would suggest two options which might work for you.
sys.path
. This would ensure that any modules that you are already importing if present in the newly included folder is never imported from that particular location.Reading your comment, I would suggest, the best option would be to add the following lines somewhere in your script but before you import`
import sys
sys.path.append('/whatever')
Upvotes: 2
Reputation: 188054
If you
import X
you only import the module X. Nothing else. Something being on your python path is not equivalent to being automatically imported (it's just importable). See also:
Upvotes: 1