I'm working on a program that needs to split and rejoin some file paths, and I'm not sure why os.path.join(*list) and os.path.sep.join(list) produce different results when there is a drive letter present in the separated path.
import os
path = 'C:\\Users\\choglan\\Desktop'
separatedPath = path.split(os.path.sep)
# ['C:', 'Users', 'choglan', 'Desktop']
path = os.path.sep.join(separatedPath)
# C:\\Users\\choglan\\Desktop
print(path)
path = os.path.join(*separatedPath)
# C:Users\\choglan\\Desktop
print(path)
Why does this happen? And should I just use os.path.sep.join(list) for my program even though os.path.join(*list) seems to be more commonly used?