1 \section{Standard Module
\sectcode{os
}}
4 This module provides a more portable way of using operating system
5 (OS) dependent functionality than importing an OS dependent built-in
6 module like
\code{posix
}.
8 When the optional built-in module
\code{posix
} is available, this
9 module exports the same functions and data as
\code{posix
}; otherwise,
10 it searches for an OS dependent built-in module like
\code{mac
} and
11 exports the same functions and data as found there. The design of all
12 Python's built-in OS dependent modules is such that as long as the same
13 functionality is available, it uses the same interface; e.g., the
14 function
\code{os.stat(
\var{file
})
} returns stat info about a
\var{file
} in a
15 format compatible with the POSIX interface.
17 Extensions peculiar to a particular OS are also available through the
18 \code{os
} module, but using them is of course a threat to portability!
20 Note that after the first time
\code{os
} is imported, there is
\emph{no
}
21 performance penalty in using functions from
\code{os
} instead of
22 directly from the OS dependent built-in module, so there should be
23 \emph{no
} reason not to use
\code{os
}!
25 In addition to whatever the correct OS dependent module exports, the
26 following variables and functions are always exported by
\code{os
}:
28 \renewcommand{\indexsubitem}{(in module os)
}
29 \begin{datadesc
}{name
}
30 The name of the OS dependent module imported, e.g.
\code{'posix'
} or
34 \begin{datadesc
}{path
}
35 The corresponding OS dependent standard module for pathname
36 operations, e.g.,
\code{posixpath
} or
\code{macpath
}. Thus, (given
37 the proper imports),
\code{os.path.split(
\var{file
})
} is equivalent to but
38 more portable than
\code{posixpath.split(
\var{file
})
}.
41 \begin{datadesc
}{curdir
}
42 The constant string used by the OS to refer to the current directory,
43 e.g.
\code{'.'
} for POSIX or
\code{':'
} for the Mac.
46 \begin{datadesc
}{pardir
}
47 The constant string used by the OS to refer to the parent directory,
48 e.g.
\code{'..'
} for POSIX or
\code{'::'
} for the Mac.
52 The character used by the OS to separate pathname components, e.g.
53 \code{'/'
} for POSIX or
\code{':'
} for the Mac. Note that knowing this
54 is not sufficient to be able to parse or concatenate pathnames---better
55 use
\code{os.path.split()
} and
\code{os.path.join()
}---but it is
59 \begin{funcdesc
}{execl
}{path\, arg0\, arg1\, ...
}
60 This is equivalent to a call to
\code{os.execv
} with an
\var{argv
}
61 of
\code{[\var{arg0
},
\var{arg1
}, ...
]}.
64 \begin{funcdesc
}{execle
}{path\, arg0\, arg1\, ...\, env
}
65 This is equivalent to a call to
\code{os.execve
} with an
\var{argv
}
66 of
\code{[\var{arg0
},
\var{arg1
}, ...
]}.
69 \begin{funcdesc
}{execlp
}{path\, arg0\, arg1\, ...
}
70 This is like
\code{execl
} but duplicates the shell's actions in
71 searching for an executable file in a list of directories. The
72 directory list is obtained from
\code{environ
['PATH'
]}.
75 \begin{funcdesc
}{execvp
}{path\, arg0\, arg1\, ...
}
76 \code{execvp
} is for
\code{execv
} what
\code{execlp
} is for
\code{execl
}.