Reputation: 197
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
Upvotes: 8
Views: 18951
Reputation: 21740
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'
Upvotes: 12