E
Elliot Peele
Why does os.path.join('/foo', '/bar') return '/bar' rather than
'/foo/bar'? That just seems rather counter intuitive.
Elliot
'/foo/bar'? That just seems rather counter intuitive.
Elliot
Why does os.path.join('/foo', '/bar') return '/bar' rather than
'/foo/bar'? That just seems rather counter intuitive.
Elliot
Why does os.path.join('/foo', '/bar') return '/bar' rather than
'/foo/bar'? That just seems rather counter intuitive.
Elliot
join( path1[, path2[, ...]])
Join one or more path components intelligently. If any component is an
absolute path, all previous components (on Windows, including the
previous drive letter, if there was one) are thrown away...
join( path1[, path2[, ...]])
Join one or more path components intelligently. If any component is an
absolute path, all previous components (on Windows, including the
previous drive letter, if there was one) are thrown away...
Yes, but that still doesn't answer my question as to why os.path.join
works that way. I understand that that is how it is written, but why?
Elliot
['/foo', 'bar']pathparts = ["/foo", "bar"]
os.path.join(pathparts)
Why does os.path.join('/foo', '/bar') return '/bar' rather than
'/foo/bar'? That just seems rather counter intuitive.
Elliot
join( path1[, path2[, ...]])
Join one or more path components intelligently. If any component is an
absolute path, all previous components (on Windows, including the
previous drive letter, if there was one) are thrown away...
Yes, but that still doesn't answer my question as to why os.path.join
works that way. I understand that that is how it is written, but why?
A better question is why this doesn't work.
['/foo', 'bar']pathparts = ["/foo", "bar"]
os.path.join(pathparts)
This should return a string in my opinion.
A better question is why this doesn't work.['/foo', 'bar']pathparts = ["/foo", "bar"]
os.path.join(pathparts)This should return a string in my opinion.
I think it's a bug, but because it should raise TypeError instead.
The right usage is os.path.join(*pathparts)
On May 1, 11:10 pm, "Gabriel Genellina" <[email protected]>
wrote:
Wow. What exactly is that * operator doing? Is it only used in
passing args to functions? Does it just expand the list into
individual string arguments for exactly this situation? Or does it
have other uses?
On May 1, 11:10 pm, "Gabriel Genellina" <[email protected]> .... ....
Wow. What exactly is that * operator doing? Is it only used in
passing args to functions? Does it just expand the list into
individual string arguments for exactly this situation? Or does it
have other uses?
1
On May 1, 11:10 pm, "Gabriel Genellina" <[email protected]> ... ...
Wow. What exactly is that * operator doing? Is it only used in
passing args to functions? Does it just expand the list into
individual string arguments for exactly this situation? Or does it
have other uses?
It's used for unpacking a collection into arguments to a function.
It's also used at the other end for receiving a variable length set of
arguments. i.e.
return a + b
return reduce(int.__add__, args)
4
The same sort of thing holds for keyword arguments:
for k in kw:
print kw[k]
1
2>>> d = {'a': 1, 'b': 10, 'c': 100}
1
100
10
Elliot Peele said:Why does os.path.join('/foo', '/bar') return '/bar' rather than
'/foo/bar'? That just seems rather counter intuitive.
Elliot
join( path1[, path2[, ...]])
Join one or more path components intelligently. If any component is an
absolute path, all previous components (on Windows, including the
previous drive letter, if there was one) are thrown away...
Yes, but that still doesn't answer my question as to why os.path.join
works that way. I understand that that is how it is written, but why?
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.