This commit was manufactured by cvs2svn to create tag 'cnrisync'.
[python/dscho.git] / Doc / lib / libos.tex
blob51442efcfcb14d32a9d188c25a98c8e6b9265d26
1 \section{Standard Module \sectcode{os}}
3 \stmodindex{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)}
30 \begin{datadesc}{name}
31 The name of the OS dependent module imported. The following names
32 have currently been registered: \code{'posix'}, \code{'nt'},
33 \code{'dos'}, \code{'mac'}.
34 \end{datadesc}
36 \begin{datadesc}{path}
37 The corresponding OS dependent standard module for pathname
38 operations, e.g., \code{posixpath} or \code{macpath}. Thus, (given
39 the proper imports), \code{os.path.split(\var{file})} is equivalent to but
40 more portable than \code{posixpath.split(\var{file})}.
41 \end{datadesc}
43 \begin{datadesc}{curdir}
44 The constant string used by the OS to refer to the current directory,
45 e.g. \code{'.'} for POSIX or \code{':'} for the Mac.
46 \end{datadesc}
48 \begin{datadesc}{pardir}
49 The constant string used by the OS to refer to the parent directory,
50 e.g. \code{'..'} for POSIX or \code{'::'} for the Mac.
51 \end{datadesc}
53 \begin{datadesc}{sep}
54 The character used by the OS to separate pathname components, e.g.\
55 \code{'/'} for POSIX or \code{':'} for the Mac. Note that knowing this
56 is not sufficient to be able to parse or concatenate pathnames---better
57 use \code{os.path.split()} and \code{os.path.join()}---but it is
58 occasionally useful.
59 \end{datadesc}
61 \begin{datadesc}{pathsep}
62 The character conventionally used by the OS to separate search patch
63 components (as in \code{\$PATH}), e.g.\ \code{':'} for POSIX or
64 \code{';'} for MS-DOS.
65 \end{datadesc}
67 \begin{datadesc}{defpath}
68 The default search path used by \code{os.exec*p*()} if the environment
69 doesn't have a \code{'PATH'} key.
70 \end{datadesc}
72 \begin{funcdesc}{execl}{path\, arg0\, arg1\, ...}
73 This is equivalent to
74 \code{os.execv(\var{path}, (\var{arg0}, \var{arg1}, ...))}.
75 \end{funcdesc}
77 \begin{funcdesc}{execle}{path\, arg0\, arg1\, ...\, env}
78 This is equivalent to
79 \code{os.execve(\var{path}, (\var{arg0}, \var{arg1}, ...), \var{env})}.
80 \end{funcdesc}
82 \begin{funcdesc}{execlp}{path\, arg0\, arg1\, ...}
83 This is equivalent to
84 \code{os.execvp(\var{path}, (\var{arg0}, \var{arg1}, ...))}.
85 \end{funcdesc}
87 \begin{funcdesc}{execvp}{path\, args}
88 This is like \code{os.execv(\var{path}, \var{args})} but duplicates
89 the shell's actions in searching for an executable file in a list of
90 directories. The directory list is obtained from
91 \code{os.environ['PATH']}.
92 \end{funcdesc}
94 \begin{funcdesc}{execvpe}{path\, args\, env}
95 This is a cross between \code{os.execve()} and \code{os.execvp()}.
96 The directory list is obtained from \code{\var{env}['PATH']}.
97 \end{funcdesc}
99 (The functions \code{os.execv()} and \code{execve()} are not
100 documented here, since they are implemented by the OS dependent
101 module. If the OS dependent module doesn't define either of these,
102 the functions that rely on it will raise an exception. They are
103 documented in the section on module \code{posix}, together with all
104 other functions that \code{os} imports from the OS dependent module.)