mirror of
https://github.com/python/cpython.git
synced 2025-08-28 04:35:02 +00:00
Added splitext()
This commit is contained in:
parent
54afb3bf60
commit
a48bf79977
1 changed files with 22 additions and 0 deletions
|
@ -46,6 +46,28 @@ def split(s):
|
|||
return s[:colon-1], s[colon:]
|
||||
|
||||
|
||||
# Split a path in root and extension.
|
||||
# The extension is everything starting at the last dot in the last
|
||||
# pathname component; the root is everything before that.
|
||||
# It is always true that root + ext == p.
|
||||
|
||||
def splitext(p):
|
||||
root, ext = '', ''
|
||||
for c in p:
|
||||
if c == ':':
|
||||
root, ext = root + ext + c, ''
|
||||
elif c == '.':
|
||||
if ext:
|
||||
root, ext = root + ext, c
|
||||
else:
|
||||
ext = c
|
||||
elif ext:
|
||||
ext = ext + c
|
||||
else:
|
||||
root = root + c
|
||||
return root, ext
|
||||
|
||||
|
||||
# Split a pathname into a drive specification and the rest of the
|
||||
# path. Useful on DOS/Windows/NT; on the Mac, the drive is always
|
||||
# empty (don't use the volume name -- it doesn't have the same
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue