Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Cpython
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
sip
Cpython
Commits
2684738d
Commit
2684738d
authored
Mar 31, 1992
by
Guido van Rossum
Browse files
Options
Downloads
Patches
Plain Diff
Renamed to posixpath; changed def'n of split().
parent
627efd94
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Lib/posixpath.py
+13
-9
13 additions, 9 deletions
Lib/posixpath.py
with
13 additions
and
9 deletions
Lib/posixpath.py
+
13
−
9
View file @
2684738d
# Module 'path' -- common operations on POSIX pathnames
# Module '
posix
path' -- common operations on POSIX pathnames
import
posix
import
stat
...
...
@@ -31,20 +31,24 @@ def join(a, b):
return
a
+
'
/
'
+
b
# Split a path in head (empty or ending in '/') and tail (no '/').
# The tail will be empty if the path ends in '/'.
# It is always true that head + tail == p; also join(head, tail) == p.
# Note that because head ends in '/', if you want to find all components
# of a path by repeatedly getting the head, you will have to strip off
# the trailing '/' yourself (another function should be defined to
# split an entire path into components.)
# Split a path in head (everything up to the last '/') and tail (the
# rest). If the original path ends in '/' but is not the root, this
# '/' is stripped. After the trailing '/' is stripped, the invariant
# join(head, tail) == p holds.
# The resulting head won't end in '/' unless it is the root.
def
split
(
p
):
if
p
[
-
1
:]
==
'
/
'
and
p
<>
'
/
'
*
len
(
p
):
while
p
[
-
1
]
==
'
/
'
:
p
=
p
[:
-
1
]
head
,
tail
=
''
,
''
for
c
in
p
:
tail
=
tail
+
c
if
c
==
'
/
'
:
head
,
tail
=
head
+
tail
,
''
if
head
[
-
1
:]
==
'
/
'
and
head
<>
'
/
'
*
len
(
head
):
while
head
[
-
1
]
==
'
/
'
:
head
=
head
[:
-
1
]
return
head
,
tail
...
...
@@ -119,7 +123,7 @@ def isdir(path):
return
stat
.
S_ISDIR
(
st
[
stat
.
ST_MODE
])
# Is a path a regula
t
file?
# Is a path a regula
r
file?
# This follows symbolic links, so both islink() and isdir() can be true
# for the same path.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment