When multiple directories need to be concatenated, as in an executable search path, there is an os-dependent separator character. For Windows it's ';'
, for Linux it's ':'
. Is there a way in Python to get which character to split on?
In the discussions to this question How do I find out my python path using python? , it is suggested that os.sep
will do it. That answer is wrong, since it is the separator for components of a directory or filename and equates to '\\'
or '/'
.
Select Start select Control Panel. double click System and select the Advanced tab. Click Environment Variables. In the section System Variables find the PATH environment variable and select it.
os.pathsep
It is os.pathsep
OK, so there are:
os.pathsep
that is ;
and which is a separator in the PATH
environment variable;os.path.sep
that is /
in Unix/Linux and \
in Windows, which is a separator between path components.The similarity is a source of confusion.
Making it a little more explicit (For python newbies like me)
import os
print(os.pathsep)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With