I use Git VC for my Python codes, mostly scripts with scientific calculations. To parse raw data (which are also part of the repository) into Python variables, I do:
import numpy as np
t_x_q_obs = np.genfromtxt('MeasuredAlgebrProductionRate_30min_18h.csv', delimiter=';')
Meanwhile, the repo has grown to contain > 100 files. So I would like to group certain kind of files, especially *.csv
files with raw data, in a subfolder. No problem with Git, but Python would not find them anymore.
In Matlab, I would just tell people to add the whole folder+subfolders to their pathdef.m
, but since Python programmers use a lot of different editors/IDEs, there is no universal how-to. I would like my scripts to be executable OOTB by anyone cloning my repo and running the scripts from the command line or his/her favorite IDE. If I added those subfolders to the PYTHONPATH
variable, this would not be universal either. Also, I would not like to hard-code the relative paths in all scripts.
Is there an elegant way to have Python look for external files which are part of the same folder structure?