[issue11344] Add height argument to os.path.dirname()
Raymond Hettinger
report at bugs.python.org
Sat Mar 5 08:59:00 CET 2011
Raymond Hettinger <rhettinger at users.sourceforge.net> added the comment:
> My point was that unix hasn't found it useful
> to add a level option to the dirname API.
ISTM, that is a strong indication that this isn't needed in the form it has been proposed.
> I don't know that I personally have ever had
> occasion to peel off more than one directory level
> without also wanting to do something with the
> intermediate results, so perhaps I am not a good
> judge of how useful this would be.
I think this only arises when a known directory structure has been attached at some arbitrary point on a tree, so you might use a relative path like ../../bin/command.py in the shell. To serve that use case, it would be better to have a function that splits all the components of the path into a list that's easily manipulated:
>>> oldpath = os.path.splitpath('/ggparent/gparent/parent/')
>>> newpath = oldpath[:-2] + ['bin', 'command.py']
>>> os.path.join(*newpath)
'/ggparent/bin/command.py'
----------
nosy: +rhettinger
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue11344>
_______________________________________
More information about the Python-bugs-list
mailing list