Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a48bf79

Browse files
committed
Added splitext()
1 parent 54afb3b commit a48bf79

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

Lib/macpath.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,28 @@ def split(s):
4646
return s[:colon-1], s[colon:]
4747

4848

49+
# Split a path in root and extension.
50+
# The extension is everything starting at the last dot in the last
51+
# pathname component; the root is everything before that.
52+
# It is always true that root + ext == p.
53+
54+
def splitext(p):
55+
root, ext = '', ''
56+
for c in p:
57+
if c == ':':
58+
root, ext = root + ext + c, ''
59+
elif c == '.':
60+
if ext:
61+
root, ext = root + ext, c
62+
else:
63+
ext = c
64+
elif ext:
65+
ext = ext + c
66+
else:
67+
root = root + c
68+
return root, ext
69+
70+
4971
# Split a pathname into a drive specification and the rest of the
5072
# path. Useful on DOS/Windows/NT; on the Mac, the drive is always
5173
# empty (don't use the volume name -- it doesn't have the same

0 commit comments

Comments
 (0)