import os.path
print os.path.abspath(__file__+'/../../..') # the directory three levels up
I was pleasantly surprised that
- abspath() managed to parse correctly, without using os.path.join()
- We didn't have to strip out the filename before we build the path
For cross platform compatibility if abspath's parsing does not work, we could use something less readable, e.g.
- os.path.sep instead of '/'
- os.path.join()