Tuffy
Tuffy

Reputation: 197

correct way of using os.path.join() in python

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

Answers (1)

suhailvs
suhailvs

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

Related Questions