It's fairly common to see people recommend that you use os.path.join()
to create file paths in Python, rather than hardcoding the path separator. In the example below, f2
is what people generally recommend:
import os.path
with open('tempdir/test1.txt', 'w') as f1 :
f1.write('Some text.')
with open(os.path.join('tempdir', 'test2.txt'), 'w') as f2:
f2.write('Some other text')
However, I've had no problems just using '/'
as a path separator on both Unix and Windows. So my question is: what are the cases when hardcoding the separator fails?