[Python-Dev] Proposal to revert r54204 (splitext change)

Shane Geiger sgeiger at ncee.net
Thu Mar 15 06:57:06 CET 2007


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 at 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
sgeiger at ncee.net  |  402-438-8958  |  http://www.ncee.net

Leading the Campaign for Economic and Financial Literacy

-------------- next part --------------
A non-text attachment was scrubbed...
Name: sgeiger.vcf
Type: text/x-vcard
Size: 297 bytes
Desc: not available
Url : http://mail.python.org/pipermail/python-dev/attachments/20070315/a12279d6/attachment.vcf 


More information about the Python-Dev mailing list