While working with OS X Lion, I am trying to open a file in my python program from anywhere in the terminal. I installed the following function in my .bash_profile:
function testprogram() {python ~/.folder/.testprogram.py}
Thus, I can (in the terminal) run my test program from a different directory than my ~ /.
Now, if I run the program in my home directory, the following will work
infile = open("folder2/test.txt", "r+")
However, if I enter another directory from my home folder and write "testprogram" in the terminal, the program starts, but cannot find the test.txt file.
Is there a way to always have python to open the file from the same place where I did not run the program?
source
share