I find myself needing to get a parent directory of a python file in a source tree that is multiple directories up with some regularity. Having to call dirname many times is clunky.
I looked around and was surprised to not find posts on this.
The general scenario is:
import os.path as op
third_degree_parent = op.dirname(op.dirname(op.dirname(op.realpath(__file__))))
Normalize a relative path;
../ is the parent, repeat it as many times as needed:
import os.path as op op.abspath(op.join(__file__, '../../..'))