Programatically Determining Bin Path
Posted
by
Andy
on Stack Overflow
See other posts from Stack Overflow
or by Andy
Published on 2014-08-22T16:16:15Z
Indexed on
2014/08/22
16:19 UTC
Read the original article
Hit count: 272
python
I'm working on a web app called pj
and there is a bin
file and a src
folder.
The relative paths before I deploy the app will look something like:
pj/bin
and pj/src/pj/script.py
.
However, after deployment, the relative paths will look like:
pj_dep/deployed/bin
and pj_dep/deployed/lib/python2.6/site-packages/pj/script.py
Question:
Within script.py
, I am trying to find the path of a file in the bin
directory. This leads to 2 different behaviors in the dev and deployment environment.
If I do
os.path.join(os.path.dirname(__file__), 'bin')
to try to get the path for the dev environment, I will have a different path for the deployment environment.
Is there a more generalized way I can find the bin directory so that I do not need to rely on an if
statement to determine how many directories to go up based on the current env? This doesn't seem flexible and might cause other issues later on when the code is moved.
© Stack Overflow or respective owner