[Python-ideas] Small enhancement to os.path.splitext
Tarek Ziadé
ziade.tarek at gmail.com
Tue Apr 20 17:35:44 CEST 2010
Hello
Currently, os.path.splitext will split a string giving you the piece
behind the last dot:
>>> os.path.splitext('file.tar.gz')
('file.tar', '.gz')
In some cases, what we really want is the two last parts when
splitting on the dots (like in my example).
What about providing an extra argument to be able to grab more than one dot ?
>>> os.path.splitext('file.tar.gz', numext=2)
('file', '.tar.gz')
If numext > numbers of dots, it will just split after the first dot:
>>> os.path.splitext('file.tar', numext=2)
('file', '.tar')
What do you think ?
Regards
Tarek
--
Tarek Ziadé | http://ziade.org
More information about the Python-ideas
mailing list