New submission from blokeley <bloke...@gmail.com>: It is a common need to find the grandparent or great-grandparent (etc.) of a given directory, which results in this:
>>> from os.path import dirname >>> mydir = dirname(dirname(dirname(path))) Could a "height" parameter be added to os.path.dirname so it becomes: >>> def dirname(path, height=1): Then we could have usage like: >>> path = '/ggparent/gparent/parent/myfile.txt' >>> from os.path import dirname >>> dirname(path) /ggparent/gparent/parent >>> dirname(path, 2) /ggparent/gparent >>> dirname(path, 3) /ggparent Perhaps we should throw ValueErrors for invalid height values: >>> dirname(path, 10) ValueError >>> dirname(path, -1) ValueError Perhaps a height of 0 should do nothing: >>> dirname(path, 0) /ggparent/gparent/parent/myfile.txt I can supply patches, unit tests and docs if you like. ---------- components: Library (Lib) messages: 129616 nosy: blokeley priority: normal severity: normal status: open title: Add height argument to os.path.dirname() type: feature request versions: Python 3.3 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue11344> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com