os
moduleThe os
module in Python provides functions that help to interact with the underlying operating system.
os
moduleThe os
module contains different separator constants that indicate different file separators used in different operating systems. The constants are as follows:
os.sep
os.altsep
os.extsep
os.pathsep
os.linesep
os.sep
The os.sep
indicates the character used by the operating system to separate pathname components. The value for os.sep
is /
for POSIX and \\
for Windows.
os.altsep
The os.altsep
represents the operating system’s alternate character for separating pathname components, or None
if only one separator character is available. On Windows systems when os.sep
is a backslash, this is set to /
.
os.extsep
The os.extsep
indicates the character which separates the base filename from the extension.
os.pathsep
The os.pathsep
indicates the character used by the operating system to separate search path components. The value for os.pathsep
is :
for POSIX and ;
for Windows.
os.linesep
The os.linesep
indicates the character used by the operating system to terminate lines. The value for os.linesep
is \n
for POSIX and \r\n
for Windows.
Let’s look at the code below:
import sys, osprint("Separators for %s operating system are as follows:" % (sys.platform))print("os.sep = ", os.sep)print("os.altsep = ", os.altsep)print("os.extsep = " , os.extsep)print("os.pathsep = ", os.pathsep)print("os.linesep = ", os.linesep)
sys.platform
constant.os.sep
.os.altsep
.os.extsep
.os.pathsep
.os.linesep
.