I have following code:
os.chdir(os.path.dirname(os.path.realpath(__file__)) + "/../test")
path.append(os.getcwd())
os.chdir(os.path.dirname(os.path.realpath(__file__)))
Which should add /../test
to python path, and it does so, and it all runs smoothly afterwards on eclipse using PyDev.
But when I lunch same app from console second os.chdir does something wrong, actually the wrong thing is in os.path.realpath(__file__)
cus it returns ../test/myFile.py
in stead of ../originalFolder/myFile.py
. Of course I can fix this by using fixed os.chdir("../originalFolder")
but that seems a bit wrong to me, but this works on both, eclipse and console.
P.S. I'm using os.getcwd()
actually because I want to make sure there isn't such folder already added, otherwise I wouldn't have to switch dir's at all
So is there anything wrong with my approach or I have messed something up? or what? :)
Thanks in advance! :)