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
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'
joran beasley said the point of os.path.join is that you don't need to worry about the seperator.c:\\` instead of c:/. I am using linux and it is strongly recommend to use / instead of using `\` you can also use some relative paths.
print? Or the raw strings? Or the backslash at the end of the path?os.path.joinis that you dont need to worry about the separator ... as such using it largely defeats the purpose ...os.path.joinis just a convenience wrapper aroundos.path.sep.join(["PATH","DIR1","DIR2",...])