They are same, but which one should I use?
http://docs.python.org/library/os.html:
os.sepThe character used by the operating system to separate pathname components. This is ‘/’ for POSIX and ‘\’ for Windows. Note that knowing this is not sufficient to be able to parse or concatenate pathnames — use os.path.split() and os.path.join() — but it is occasionally useful. Also available via os.path.
I’d use
os.path.septo make it very clear that it’s the path separator… But consistency is more important, so if one is already being used, use that. Otherwise, pick one and use it all the time.Edit: Just to make sure you’re not reinventing the wheel, though, the
pathmodule already hasjoin,split,dirname, andbasenamefunctions… So you should rarely need to useos.sep: