I have some code in a project which I’d like to reuse in another project. What do I need to do (in both folders) so that I can do this?
The directory structure is something like:
- Foo
- Project1
- file1.py
- file2.py
- Project1
- Bar
- Project2
- fileX.py
- fileY.py
- Project2
I want to use functions from file1.py and file2.py in fileX.py and fileY.py.
Ideally both projects will be an installable python package, replete with __init__.py and setup.py. They could then be installed with
python setup.py installor similar.If that is not possible, don’t use
execfile()! Manipulate thePYTHONPATHto addFooso thatimport Project1.file1works.For example, from Project2/fileX.py:
However, the real answer is to make each a discrete installable package.