Bruno Bruno - 3 months ago 9
Python Question

central path for python modules

I am starting to convert a lot of C stuff in python 3.

In C I defined a directory called "Toolbox", where i put all my functions i needed in different programs, so called libraries.

To use a specific library i had just to add the line

#include "/home/User/Toolbox/VectorFunctions.h"


into my source. So i was able to use the same library in different sources.

In python i tried to write some Toolbox functions and implement them into the source with import VectorFunctions, which works, as long as the file VectorFunctions.py is in the same directory as the source.

I there a way (I think there must be one...) telling python that VectorFunctions.py is located in a different directory, e.g. /home/User/Python_Toolbox?

Thanks for any comment!

Answer

You can use python path. Writing this code beginning of your program :

import sys
sys.path.append('/home/User/Python_Toolbox')

If you have VectorFunctions.py in this folder you can import it :

import VectorFunctions