diff options
author | Barry Warsaw <barry@python.org> | 1997-02-18 21:53:25 (GMT) |
---|---|---|
committer | Barry Warsaw <barry@python.org> | 1997-02-18 21:53:25 (GMT) |
commit | 384d249006b786b7d1eed21795a83a5ab703cb96 (patch) | |
tree | 06c3626a8e9239e23f6edc7771821e9b550bb4e1 /Lib/posixpath.py | |
parent | 736bb0659fba85392e5b2034ed492a9e8bfad8d9 (diff) | |
download | cpython-384d249006b786b7d1eed21795a83a5ab703cb96.zip cpython-384d249006b786b7d1eed21795a83a5ab703cb96.tar.gz cpython-384d249006b786b7d1eed21795a83a5ab703cb96.tar.bz2 |
join(): join one or more path components
Diffstat (limited to 'Lib/posixpath.py')
-rw-r--r-- | Lib/posixpath.py | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/Lib/posixpath.py b/Lib/posixpath.py index 014dfe2..965184b 100644 --- a/Lib/posixpath.py +++ b/Lib/posixpath.py @@ -26,15 +26,20 @@ def isabs(s): return s[:1] == '/' -# Join two pathnames. -# Ignore the first part if the second part is absolute. +# Join pathnames. +# Ignore the previous parts if a part is absolute. # Insert a '/' unless the first part is empty or already ends in '/'. -def join(a, b): - if b[:1] == '/': return b - if a == '' or a[-1:] == '/': return a + b - # Note: join('x', '') returns 'x/'; is this what we want? - return a + '/' + b +def join(a, *p): + path = a + for b in p: + if b[:1] == '/': + path = b + elif path == '' or path[-1:] == '/': + path = path + b + else: + path = path + '/' + b + return path # Split a path in head (everything up to the last '/') and tail (the |