mirror of
https://github.com/python/cpython.git
synced 2025-07-29 06:05:00 +00:00
Fix splitext() to go up to the last dot, not the first.
This commit is contained in:
parent
76f587b7f8
commit
73e122f563
1 changed files with 8 additions and 3 deletions
|
@ -83,16 +83,21 @@ def split(p):
|
|||
|
||||
|
||||
# Split a path in root and extension.
|
||||
# The extension is everything starting at the first dot in the last
|
||||
# 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 in '/\\':
|
||||
if c in ['/','\\']:
|
||||
root, ext = root + ext + c, ''
|
||||
elif c == '.' or ext:
|
||||
elif c == '.':
|
||||
if ext:
|
||||
root, ext = root + ext, c
|
||||
else:
|
||||
ext = c
|
||||
elif ext:
|
||||
ext = ext + c
|
||||
else:
|
||||
root = root + c
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue