Good, we have gotten around to discussing a little annoyance I've noticed. I think this should behave similar to the way a Unix admin who is familiar with basename(1) would behave:

$ basename -s .py /tmp/foo.py foo $
$ basename /tmp/foo.py .py
foo
$ basename /tmp/foo.py /tmp/fffff.py
foo.py
$ basename -a /tmp/foo.py /tmp/fffff.py
foo.py
fffff.py
$ basename -a /tmp/foo.py /tmp/fffff.py .py
foo.py
fffff.py
.py
$ basename -s .py -a /tmp/foo.py /tmp/fffff.py .py
foo
fffff
.py
$ basename -s .py -a /tmp/foo.py /tmp/fffff.py foo
fffff
$


Changing the function name shouldn't be the solution, imho. Changing the arguments, however, should be.



Compare the documentation yourself:
-----      MANPAGE DOCUMENTATION
NAME basename, dirname -- return filename or directory portion of pathname SYNOPSIS basename string [suffix] basename [-a] [-s suffix] string [...] dirname string ----- ----- PYTHON DOCUMENTATION: Help on function basename in module posixpath: basename(p) Returns the final component of a pathname -----






Greg Ewing wrote:
Michael Urman wrote:
Who would rather see os.path.dropext(path)?

I'd like to see such a function, and also
maybe replaceext(path, new_ext). I often
end up coding things like these myself,
since indexing the result of splitext all
the time is rather ugly.

To round off the set, I suggest

    path.dropext(path)  # returns the base name
    path.getext(path)   # returns the extension
    path.replaceext(path, newext) # adds or replaces the extension

--
Greg
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/sgeiger%40ncee.net

--
Shane Geiger
IT Director
National Council on Economic Education
[EMAIL PROTECTED]  |  402-438-8958  |  http://www.ncee.net

Leading the Campaign for Economic and Financial Literacy

begin:vcard
fn:Shane Geiger
n:Geiger;Shane
org:National Council on Economic Education (NCEE)
adr:Suite 215;;201 N. 8th Street;Lincoln;NE;68508;United States
email;internet:[EMAIL PROTECTED]
title:IT Director
tel;work:402-438-8958
x-mozilla-html:FALSE
url:http://www.ncee.net
version:2.1
end:vcard

_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to