[Python-ideas] os.path.join

Ryan Hiebert ryan at ryanhiebert.com
Sun Nov 3 04:12:19 CET 2013


IIRC correctly the form 'd:efg' refers to a relative path on the d:
drive, based on the current working directory _of that drive_. Since
it requires a default base path to be relative on, that form wouldn't
work cross drives. However if we used the same drive, we might be
willing to allow a relative path prefixed with a  drive letter.

os.path.join(r'c:\abc\foo', 'd:efg') # ERROR
os.path.join(r'd:\abc\foo', 'd:efg') # returns r'd:\abc\efg'

On Sat, Nov 2, 2013 at 9:15 PM,  <random832 at fastmail.us> wrote:
> On Wed, Oct 30, 2013, at 13:06, Bruce Leban wrote:
>> >>> os.path.join(r'c:\abc', r'\def\g')   # Windows paths
>> '\\def\\g'
>>
>> On Windows \def\g is a drive-relative path not an absolute path. To get
>> the
>> right result you need to do:
>>
>> >>> drive, path = os.path.splitdrive(r'c:\abc')
>> >>> drive + os.path.join(path, r'/def/g')
>> 'c:/def/g'
>
> What should it do in the opposite case: where the path is a relative
> path on another drive? I.e. os.path.join('c:\\abc','d:efg'). This is
> archaic, sure, but if we're going to say it's always equivalent to "as
> if the first argument were the cwd", this needs to be handled too.
> Fortunately, I don't think there's any way to specify this with a UNC
> share.
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas


More information about the Python-ideas mailing list