7 Oct
2012
7 Oct
'12
1:41 a.m.
On 07/10/12 04:08, Antoine Pitrou wrote:
Personally, I cringe everytime I have to type `os.path.dirname(os.path.dirname(os.path.dirname(...)))` to go two directories upwards of a given path. Compare, with, say:
I would cringe too if I did that, because it goes THREE directories up, not two: py> path = '/a/b/c/d' py> os.path.dirname(os.path.dirname(os.path.dirname(path))) '/a' :)
p = Path('/a/b/c/d') p.parent(2) PosixPath('/a/b')
You know, I don't think I've ever needed to call dirname more than once at a time, but if I was using it a lot: parent = os.path.dirname parent(parent(parent(p)) which is not as short as p.parent(3), but it's still pretty clear. -- Steven