[issue11344] Add height argument to os.path.dirname()

2011-03-08 Thread Antoine Pitrou
Antoine Pitrou added the comment: > If I wrote the patches, tests and docs, what are the chances of it > being accepted? Rather high as far as I'm concerned. Be careful with semantics and implementation under Windows, though (you should probably take a look at existing functions in ntpath.py

[issue11344] Add height argument to os.path.dirname()

2011-03-08 Thread blokeley
blokeley added the comment: os.path.splitpath() as described by rhettinger would solve the problem. If I wrote the patches, tests and docs, what are the chances of it being accepted? -- ___ Python tracker __

[issue11344] Add height argument to os.path.dirname()

2011-03-05 Thread R. David Murray
R. David Murray added the comment: Ah, yes, splitpath is a function I've occasionally wanted. I also remember being surprised that os.path.split didn't return such a list. -- ___ Python tracker _

[issue11344] Add height argument to os.path.dirname()

2011-03-04 Thread Raymond Hettinger
Raymond Hettinger 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 m

[issue11344] Add height argument to os.path.dirname()

2011-03-04 Thread Antoine Pitrou
Antoine Pitrou added the comment: As for use cases, I have used it quite commonly in test scripts in order to find out the base directory of the source tree (and/or other resources such as data files). e.g.: basepath = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) --

[issue11344] Add height argument to os.path.dirname()

2011-03-04 Thread Antoine Pitrou
Antoine Pitrou added the comment: Except that dirname() isn't a one-liner, so you are giving rather bad advice here. -- ___ Python tracker ___ _

[issue11344] Add height argument to os.path.dirname()

2011-03-04 Thread Terry J. Reedy
Terry J. Reedy added the comment: I am inclined to -1 also. a. The proposed behavior is anti-obvious to me: the higher the height, the shorter the result. Calling param 'drop' would be better. b. Not every one-liner should be wrapped. >>> path.rsplit('/',0)[0] '/ggparent/gparent/parent/myfil

[issue11344] Add height argument to os.path.dirname()

2011-02-27 Thread R. David Murray
R. David Murray added the comment: No, it isn't a design principle. My point was that unix hasn't found it useful to add a level option to the dirname API. 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 wit

[issue11344] Add height argument to os.path.dirname()

2011-02-27 Thread Antoine Pitrou
Antoine Pitrou added the comment: Well, on the other hand, it *is* a common need. (and I don't think mimicking the shell is a design principle for Python) -- nosy: +pitrou ___ Python tracker __

[issue11344] Add height argument to os.path.dirname()

2011-02-27 Thread R. David Murray
R. David Murray added the comment: I'm -1 on this feature request. I think it is an unnecessary complication of the API, especially since dirname corresponds to the unix shell 'dirname' command, which doesn't have such a feature. If you need this feature in a particular application, it is e

[issue11344] Add height argument to os.path.dirname()

2011-02-27 Thread blokeley
New submission from blokeley : 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: