import os print(os.getcwd()) print("/".join(os.path.dirname(os.path.abspath(__file__)).split("/"))) bogon:testdir macname$pwd /Users/macname/Desktop/testdir bogon:testdir macname$ python3 ../test2.py /Users/macname/Desktop/testdir /Users/macname/Desktop