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

Skip to content

Commit 73e122f

Browse files
committed
Fix splitext() to go up to the last dot, not the first.
1 parent 76f587b commit 73e122f

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

Lib/ntpath.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,21 @@ def split(p):
8383

8484

8585
# Split a path in root and extension.
86-
# The extension is everything starting at the first dot in the last
86+
# The extension is everything starting at the last dot in the last
8787
# pathname component; the root is everything before that.
8888
# It is always true that root + ext == p.
8989

9090
def splitext(p):
9191
root, ext = '', ''
9292
for c in p:
93-
if c in '/\\':
93+
if c in ['/','\\']:
9494
root, ext = root + ext + c, ''
95-
elif c == '.' or ext:
95+
elif c == '.':
96+
if ext:
97+
root, ext = root + ext, c
98+
else:
99+
ext = c
100+
elif ext:
96101
ext = ext + c
97102
else:
98103
root = root + c

0 commit comments

Comments
 (0)