-1

When doing os.path.join('hello', '/hello', 'world') the result will be '/hello/world'

The documentation states "If a component is an absolute path, all previous components are thrown away and joining continues from the absolute path component" So python sees '/hello' as an absolute path.

Now when you have a website and use for example <a href="/hello>hello</a> it's a relative path?(referring to stackoverflow answer)

Community
  • 1
  • 1

2 Answers2

1

The way that a parameter is interpreted is completely up to the program or function interpreting it. When dealing with file system paths in python, the leading slash, by convention, refers to the root of the filesystem. However, in the web world, the root of the server's filesystem isn't publicly accessible (hopefully) or relevant to anyone browsing the site, so the convention there is that a leading slash refers to the root of the domain.

In your html example, I would argue that the /hello path is still absolute, it's just that the root is defined to be the domain, not the root of the servers's filesystem.

Justin Buchanan
  • 404
  • 3
  • 9
0

A URL is made up of several components. One of which is a path. That path could be absolute (/hello/world) or relative to the page it's on (hello/world). In the case you describe both paths are absolute.

However another component of a URL is the host. In your href example your URL does not specify a host which makes it relative to the server/hostname. So the path isn't relative, but the server is.

If the page is served on local host that href will resolve to something like http://localhost/hello/world, however if it's being served by example.com it will resolve to http://example.com/hello/world

(Assuming the scheme is http it could be something else)

nephlm
  • 543
  • 3
  • 11