[docs] Found a bug in the os.path.join function
Tim Golden
mail at timgolden.me.uk
Fri Dec 11 01:13:47 EST 2015
On 11/12/2015 00:30, Ryan McCafferty wrote:
> Hello,
>
> I am running python v3.4.2 on a Raspberry Pi 2 running raspbian jesse. I
> found what I think is a bug with the os.path.join function. When passing
> multiple arguments to this function, which is usually the case, if any
> of the arguments contain a leading slash, all of the arguments that come
> before the one with the leading slash get truncated from the resulting path.
>
> | >>> os.path.join('a', 'b', 'c') 'a/b/c' # this is expected >>>
> os.path.join('a', '/b', 'c') '/b/c' # expecting a/b/c >>>
> os.path.join('a', 'b', '/c') '/c' # expecting a/b/c >>>
> os.path.join('a', '/b', '/c') '/c' # expecting a/b/c |
>
>
> I think this is a bug, because I believe the reasoning for these path
> join functions is so users do not have to worry about which path
> components contain leading or trailing slashes.
Ryan, the documentation for os.path.join:
https://docs.python.org/3.4/library/os.path.html#os.path.join
explicitly mentions this behaviour: "... If a component is an absolute
path, all previous components are thrown away and joining continues from
the absolute path component."
So, while it might not match your intuition, it's not a bug either in
the code or in the docs.
TJG
More information about the docs
mailing list