I came across this python function os.path.join(). I wanted to know which was a preferred method of using it.
os.path.join(r'C:\\' , r'some_dir_in_C_folder')
or
print os.path.join("C:\\" , "some_dir_in_C_folder\\")
TIA
path. join() method in Python join one or more path components intelligently. This method concatenates various path components with exactly one directory separator ('/') following each non-empty part except the last path component.
To join the path in Python, use the os. path. join() function. The os.
os. path. join combines path names into one complete path. This means that you can merge multiple parts of a path into one, instead of hard-coding every path name manually.
both are incorrect, the correct usage is(for eg: c:/programs/myfiles/cat.txt
:
>>> import os
>>> os.path.join('C:/' , 'programs','myfiles','cat.txt')
'C:/programs/myfiles/cat.txt'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With