I have a script that's two directories down.
❯ tree
.
└── foo
└── bar
└── test.py
❯ cd foo/bar
❯ cat test.py
from pathlib import Path
print(Path(__file__).parent)
print(Path(__file__).parent.parent)
When I run it from the directory that contains it, PathLib thinks that the file's grandparent is the same as its parent.
❯ python test.py
. # <-- same
. # <-- directories
But when I run it from the top level, PathLib behaves correctly.
❯ cd ../..
❯ python foo/bar/test.py
foo/bar # <-- different
foo # <-- directories
Am I misunderstanding something about PathLib's API, or is something else causing its output to be sensitive to my working directory?