1

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!

asked Aug 22, 2016 at 11:18
1
  • 1
    What? This was a bad idea in C and is so in Python as well Commented Aug 22, 2016 at 11:38

2 Answers 2

3

What I would do is to organize these toolbox functions into one installable Python package bruno_toolbox, with its setup.py, and then install it into development mode to system site packages, using python setup.py develop, and then use the bruno_toolbox like any other package on the system, everywhere. Then if that package feels useful, I'd publish it to PyPI for the benefit of everyone.

answered Aug 22, 2016 at 11:42
Sign up to request clarification or add additional context in comments.

Comments

1

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
answered Aug 22, 2016 at 11:32

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.