blokeley bloke...@gmail.com 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 rep...@bugs.python.org
Antoine Pitrou pit...@free.fr 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
R. David Murray rdmur...@bitdance.com 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 rep...@bugs.python.org
Terry J. Reedy tjre...@udel.edu 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]
Antoine Pitrou pit...@free.fr added the comment:
Except that dirname() isn't a one-liner, so you are giving rather bad advice
here.
--
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11344
Antoine Pitrou pit...@free.fr 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 =
Raymond Hettinger rhettin...@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
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
R. David Murray rdmur...@bitdance.com 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
Antoine Pitrou pit...@free.fr 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 rep...@bugs.python.org
R. David Murray rdmur...@bitdance.com 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
11 matches
Mail list logo