[Python-ideas] PEP 428 - object-oriented filesystem paths

Antoine Pitrou solipsis at pitrou.net
Sun Oct 7 12:15:53 CEST 2012


On Sun, 07 Oct 2012 12:41:44 +1100
Steven D'Aprano <steve at pearwood.info> wrote:

> 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'

Not if d is a file, actually (yes, the formulation was a bit ambiguous).

Regards

Antoine.


-- 
Software development and contracting: http://pro.pitrou.net





More information about the Python-ideas mailing list