Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (16.4k points)

The beneath code won't join when debugged the order doesn't store the entire way yet the last section. 

os.path.join('/home/build/test/sandboxes/', todaystr, '/new_sandbox/')

At the point when I test this, it just stores the/new_sandbox/part of the code.

1 Answer

0 votes
by (26.4k points)

The last strings shouldn't begin with a slash. In the event that they start with a slash, at that point they're viewed as an "absolute path" and everything before them is disposed of. 

Citing the Python docs for os.path.join:

If a component is an absolute path, all previous components are thrown away and joining continues from the absolute path component.

Note on Windows, the conduct according to driving letters, which appears to have changed contrasted with before Python forms:

On Windows, the drive letter is not reset when an absolute path component (e.g., r'\foo') is encountered. If a component contains a drive letter, all previous components are thrown away and the drive letter is reset. Note that since there is a current directory for each drive, os.path.join("c:", "foo") represents a path relative to the current directory on drive C: (c:foo), not c:\foo.

Want to become a expert in python? Join the python course fast!

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Jul 18, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer

Browse Categories

...