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