os.path.normpath(pathname)
should also be mentioned as it converts /
path separators into \
separators on Windows. It also collapses redundant uplevel references... i.e., A/B
and A/foo/../B
and A/./B
all become A/B
. And if you are Windows, these all become A\B
.