blob: f8cda4cd9349cb0179c6fc4dfa2deb6acf46794a [file] [log] [blame]
Fred Drake295da241998-08-10 19:42:37 +00001\section{\module{os} ---
Fred Drake8ee679f2001-07-14 02:50:55 +00002 Miscellaneous operating system interfaces}
Fred Drakeb91e9341998-07-23 17:59:49 +00003
Fred Drakeec6baaf1999-04-21 18:13:31 +00004\declaremodule{standard}{os}
Fred Drake8ee679f2001-07-14 02:50:55 +00005\modulesynopsis{Miscellaneous operating system interfaces.}
Fred Drakeb91e9341998-07-23 17:59:49 +00006
Fred Drakec4f15af1998-03-10 03:17:26 +00007
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00008This module provides a more portable way of using operating system
Fred Drake8ee679f2001-07-14 02:50:55 +00009dependent functionality than importing a operating system dependent
10built-in module like \refmodule{posix} or \module{nt}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000011
Fred Drake8ee679f2001-07-14 02:50:55 +000012This module searches for an operating system dependent built-in module like
Fred Drake2f979011999-06-11 18:28:37 +000013\module{mac} or \refmodule{posix} and exports the same functions and data
Fred Drake8ee679f2001-07-14 02:50:55 +000014as found there. The design of all Python's built-in operating system dependent
Fred Drake215fe2f1999-02-02 19:02:35 +000015modules is such that as long as the same functionality is available,
Fred Drake907e76b2001-07-06 20:30:11 +000016it uses the same interface; for example, the function
Fred Drakeec6baaf1999-04-21 18:13:31 +000017\code{os.stat(\var{path})} returns stat information about \var{path} in
18the same format (which happens to have originated with the
19\POSIX{} interface).
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000020
Fred Drake8ee679f2001-07-14 02:50:55 +000021Extensions peculiar to a particular operating system are also
22available through the \module{os} module, but using them is of course a
23threat to portability!
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000024
Fred Drakec4f15af1998-03-10 03:17:26 +000025Note that after the first time \module{os} is imported, there is
26\emph{no} performance penalty in using functions from \module{os}
Fred Drake8ee679f2001-07-14 02:50:55 +000027instead of directly from the operating system dependent built-in module,
28so there should be \emph{no} reason not to use \module{os}!
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000029
Fred Drake215fe2f1999-02-02 19:02:35 +000030
Fred Drake859dc531999-07-01 13:54:40 +000031% Frank Stajano <fstajano@uk.research.att.com> complained that it
32% wasn't clear that the entries described in the subsections were all
33% available at the module level (most uses of subsections are
34% different); I think this is only a problem for the HTML version,
35% where the relationship may not be as clear.
36%
37\ifhtml
38The \module{os} module contains many functions and data values.
39The items below and in the following sub-sections are all available
40directly from the \module{os} module.
41\fi
42
43
Fred Drake215fe2f1999-02-02 19:02:35 +000044\begin{excdesc}{error}
Fred Drake907e76b2001-07-06 20:30:11 +000045This exception is raised when a function returns a system-related
46error (not for illegal argument types or other incidental errors).
47This is also known as the built-in exception \exception{OSError}. The
Fred Drake215fe2f1999-02-02 19:02:35 +000048accompanying value is a pair containing the numeric error code from
49\cdata{errno} and the corresponding string, as would be printed by the
50C function \cfunction{perror()}. See the module
51\refmodule{errno}\refbimodindex{errno}, which contains names for the
52error codes defined by the underlying operating system.
53
54When exceptions are classes, this exception carries two attributes,
55\member{errno} and \member{strerror}. The first holds the value of
56the C \cdata{errno} variable, and the latter holds the corresponding
57error message from \cfunction{strerror()}. For exceptions that
Fred Drake907e76b2001-07-06 20:30:11 +000058involve a file system path (such as \function{chdir()} or
Fred Drake215fe2f1999-02-02 19:02:35 +000059\function{unlink()}), the exception instance will contain a third
60attribute, \member{filename}, which is the file name passed to the
61function.
Fred Drake215fe2f1999-02-02 19:02:35 +000062\end{excdesc}
Guido van Rossum470be141995-03-17 16:07:09 +000063
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000064\begin{datadesc}{name}
Fred Drake8ee679f2001-07-14 02:50:55 +000065The name of the operating system dependent module imported. The
Fred Drake6995bb62001-11-29 20:48:44 +000066following names have currently been registered: \code{'posix'},
67\code{'nt'}, \code{'dos'}, \code{'mac'}, \code{'os2'}, \code{'ce'},
68\code{'java'}, \code{'riscos'}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000069\end{datadesc}
70
71\begin{datadesc}{path}
Fred Drake8ee679f2001-07-14 02:50:55 +000072The corresponding operating system dependent standard module for pathname
Fred Drake907e76b2001-07-06 20:30:11 +000073operations, such as \module{posixpath} or \module{macpath}. Thus,
74given the proper imports, \code{os.path.split(\var{file})} is
75equivalent to but more portable than
76\code{posixpath.split(\var{file})}. Note that this is also an
77importable module: it may be imported directly as
Fred Drake215fe2f1999-02-02 19:02:35 +000078\refmodule{os.path}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000079\end{datadesc}
80
Fred Drake215fe2f1999-02-02 19:02:35 +000081
82
83\subsection{Process Parameters \label{os-procinfo}}
84
85These functions and data items provide information and operate on the
86current process and user.
87
Fred Drake215fe2f1999-02-02 19:02:35 +000088\begin{datadesc}{environ}
Fred Drake0e1de8b1999-04-29 12:57:32 +000089A mapping object representing the string environment. For example,
90\code{environ['HOME']} is the pathname of your home directory (on some
91platforms), and is equivalent to \code{getenv("HOME")} in C.
Fred Drake215fe2f1999-02-02 19:02:35 +000092
93If the platform supports the \function{putenv()} function, this
94mapping may be used to modify the environment as well as query the
95environment. \function{putenv()} will be called automatically when
96the mapping is modified.
97
98If \function{putenv()} is not provided, this mapping may be passed to
99the appropriate process-creation functions to cause child processes to
100use a modified environment.
101\end{datadesc}
102
Fred Drake6db897c1999-07-12 16:49:30 +0000103\begin{funcdescni}{chdir}{path}
104\funclineni{getcwd}{}
105These functions are described in ``Files and Directories'' (section
106\ref{os-file-dir}).
107\end{funcdescni}
Fred Drake215fe2f1999-02-02 19:02:35 +0000108
Fred Drake18f7a451999-12-09 22:11:43 +0000109\begin{funcdesc}{ctermid}{}
110Return the filename corresponding to the controlling terminal of the
111process.
Fred Drakec37b65e2001-11-28 07:26:15 +0000112Availability: \UNIX.
Fred Drake18f7a451999-12-09 22:11:43 +0000113\end{funcdesc}
114
Fred Drake215fe2f1999-02-02 19:02:35 +0000115\begin{funcdesc}{getegid}{}
116Return the current process' effective group id.
Fred Drakec37b65e2001-11-28 07:26:15 +0000117Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +0000118\end{funcdesc}
119
120\begin{funcdesc}{geteuid}{}
Fred Drake6b330ba81999-05-25 13:42:26 +0000121\index{user!effective id}
Fred Drake215fe2f1999-02-02 19:02:35 +0000122Return the current process' effective user id.
Fred Drakec37b65e2001-11-28 07:26:15 +0000123Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +0000124\end{funcdesc}
125
126\begin{funcdesc}{getgid}{}
Fred Drake6b330ba81999-05-25 13:42:26 +0000127\index{process!group}
Fred Drake215fe2f1999-02-02 19:02:35 +0000128Return the current process' group id.
Fred Drakec37b65e2001-11-28 07:26:15 +0000129Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +0000130\end{funcdesc}
131
Fred Drake88f6ca21999-12-15 19:39:04 +0000132\begin{funcdesc}{getgroups}{}
133Return list of supplemental group ids associated with the current
134process.
Fred Drakec37b65e2001-11-28 07:26:15 +0000135Availability: \UNIX.
Fred Drake88f6ca21999-12-15 19:39:04 +0000136\end{funcdesc}
137
138\begin{funcdesc}{getlogin}{}
139Return the actual login name for the current process, even if there
140are multiple login names which map to the same user id.
Fred Drakec37b65e2001-11-28 07:26:15 +0000141Availability: \UNIX.
Fred Drake88f6ca21999-12-15 19:39:04 +0000142\end{funcdesc}
143
Fred Drake215fe2f1999-02-02 19:02:35 +0000144\begin{funcdesc}{getpgrp}{}
145\index{process!group}
146Return the current process group id.
Fred Drakec37b65e2001-11-28 07:26:15 +0000147Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +0000148\end{funcdesc}
149
150\begin{funcdesc}{getpid}{}
151\index{process!id}
152Return the current process id.
Fred Drakec37b65e2001-11-28 07:26:15 +0000153Availability: \UNIX, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000154\end{funcdesc}
155
156\begin{funcdesc}{getppid}{}
157\index{process!id of parent}
158Return the parent's process id.
Fred Drakec37b65e2001-11-28 07:26:15 +0000159Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +0000160\end{funcdesc}
161
162\begin{funcdesc}{getuid}{}
Fred Drake6b330ba81999-05-25 13:42:26 +0000163\index{user!id}
Fred Drake215fe2f1999-02-02 19:02:35 +0000164Return the current process' user id.
Fred Drakec37b65e2001-11-28 07:26:15 +0000165Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +0000166\end{funcdesc}
167
Fred Drake81e142b2001-05-31 20:27:46 +0000168\begin{funcdesc}{getenv}{varname\optional{, value}}
169Return the value of the environment variable \var{varname} if it
170exists, or \var{value} if it doesn't. \var{value} defaults to
171\code{None}.
Fred Drakec37b65e2001-11-28 07:26:15 +0000172Availability: most flavors of \UNIX, Windows.
Fred Drake81e142b2001-05-31 20:27:46 +0000173\end{funcdesc}
174
Fred Drake215fe2f1999-02-02 19:02:35 +0000175\begin{funcdesc}{putenv}{varname, value}
176\index{environment variables!setting}
177Set the environment variable named \var{varname} to the string
178\var{value}. Such changes to the environment affect subprocesses
179started with \function{os.system()}, \function{popen()} or
180\function{fork()} and \function{execv()}.
Fred Drakec37b65e2001-11-28 07:26:15 +0000181Availability: most flavors of \UNIX, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000182
183When \function{putenv()} is
184supported, assignments to items in \code{os.environ} are automatically
185translated into corresponding calls to \function{putenv()}; however,
186calls to \function{putenv()} don't update \code{os.environ}, so it is
187actually preferable to assign to items of \code{os.environ}.
188\end{funcdesc}
189
Andrew M. Kuchling8d2f2b22000-07-13 01:26:58 +0000190\begin{funcdesc}{setegid}{egid}
191Set the current process's effective group id.
Fred Drakec37b65e2001-11-28 07:26:15 +0000192Availability: \UNIX.
Andrew M. Kuchling8d2f2b22000-07-13 01:26:58 +0000193\end{funcdesc}
194
195\begin{funcdesc}{seteuid}{euid}
196Set the current process's effective user id.
Fred Drakec37b65e2001-11-28 07:26:15 +0000197Availability: \UNIX.
Andrew M. Kuchling8d2f2b22000-07-13 01:26:58 +0000198\end{funcdesc}
199
Fred Drake215fe2f1999-02-02 19:02:35 +0000200\begin{funcdesc}{setgid}{gid}
201Set the current process' group id.
Fred Drakec37b65e2001-11-28 07:26:15 +0000202Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +0000203\end{funcdesc}
204
Martin v. Löwis61c5edf2001-10-18 04:06:00 +0000205\begin{funcdesc}{setgroups}{groups}
Martin v. Löwisc4051332001-10-18 14:07:12 +0000206Set the list of supplemental group ids associated with the current
207process to \var{groups}. \var{groups} must be a sequence, and each
208element must be an integer identifying a group. This operation is
209typical available only to the superuser.
Fred Drakec37b65e2001-11-28 07:26:15 +0000210Availability: \UNIX.
Martin v. Löwis61c5edf2001-10-18 04:06:00 +0000211\versionadded{2.2}
212\end{funcdesc}
213
Fred Drake215fe2f1999-02-02 19:02:35 +0000214\begin{funcdesc}{setpgrp}{}
215Calls the system call \cfunction{setpgrp()} or \cfunction{setpgrp(0,
2160)} depending on which version is implemented (if any). See the
217\UNIX{} manual for the semantics.
Fred Drakec37b65e2001-11-28 07:26:15 +0000218Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +0000219\end{funcdesc}
220
221\begin{funcdesc}{setpgid}{pid, pgrp}
222Calls the system call \cfunction{setpgid()}. See the \UNIX{} manual
223for the semantics.
Fred Drakec37b65e2001-11-28 07:26:15 +0000224Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +0000225\end{funcdesc}
226
Andrew M. Kuchling8d2f2b22000-07-13 01:26:58 +0000227\begin{funcdesc}{setreuid}{ruid, euid}
228Set the current process's real and effective user ids.
Fred Drakec37b65e2001-11-28 07:26:15 +0000229Availability: \UNIX.
Andrew M. Kuchling8d2f2b22000-07-13 01:26:58 +0000230\end{funcdesc}
231
232\begin{funcdesc}{setregid}{rgid, egid}
233Set the current process's real and effective group ids.
Fred Drakec37b65e2001-11-28 07:26:15 +0000234Availability: \UNIX.
Andrew M. Kuchling8d2f2b22000-07-13 01:26:58 +0000235\end{funcdesc}
236
Fred Drake215fe2f1999-02-02 19:02:35 +0000237\begin{funcdesc}{setsid}{}
238Calls the system call \cfunction{setsid()}. See the \UNIX{} manual
239for the semantics.
Fred Drakec37b65e2001-11-28 07:26:15 +0000240Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +0000241\end{funcdesc}
242
243\begin{funcdesc}{setuid}{uid}
Fred Drake6b330ba81999-05-25 13:42:26 +0000244\index{user!id, setting}
Fred Drake215fe2f1999-02-02 19:02:35 +0000245Set the current process' user id.
Fred Drakec37b65e2001-11-28 07:26:15 +0000246Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +0000247\end{funcdesc}
248
249% placed in this section since it relates to errno.... a little weak ;-(
250\begin{funcdesc}{strerror}{code}
251Return the error message corresponding to the error code in
252\var{code}.
Fred Drakec37b65e2001-11-28 07:26:15 +0000253Availability: \UNIX, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000254\end{funcdesc}
255
256\begin{funcdesc}{umask}{mask}
257Set the current numeric umask and returns the previous umask.
Fred Drakec37b65e2001-11-28 07:26:15 +0000258Availability: \UNIX, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000259\end{funcdesc}
260
261\begin{funcdesc}{uname}{}
262Return a 5-tuple containing information identifying the current
263operating system. The tuple contains 5 strings:
264\code{(\var{sysname}, \var{nodename}, \var{release}, \var{version},
265\var{machine})}. Some systems truncate the nodename to 8
266characters or to the leading component; a better way to get the
267hostname is \function{socket.gethostname()}
268\withsubitem{(in module socket)}{\ttindex{gethostname()}}
269or even
270\withsubitem{(in module socket)}{\ttindex{gethostbyaddr()}}
271\code{socket.gethostbyaddr(socket.gethostname())}.
Fred Drakec37b65e2001-11-28 07:26:15 +0000272Availability: recent flavors of \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +0000273\end{funcdesc}
274
275
276
277\subsection{File Object Creation \label{os-newstreams}}
278
279These functions create new file objects.
280
281
282\begin{funcdesc}{fdopen}{fd\optional{, mode\optional{, bufsize}}}
283Return an open file object connected to the file descriptor \var{fd}.
Fred Drake8c9fc001999-08-05 13:41:31 +0000284\index{I/O control!buffering}
Fred Drake215fe2f1999-02-02 19:02:35 +0000285The \var{mode} and \var{bufsize} arguments have the same meaning as
286the corresponding arguments to the built-in \function{open()}
287function.
Fred Drakec37b65e2001-11-28 07:26:15 +0000288Availability: Macintosh, \UNIX, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000289\end{funcdesc}
290
291\begin{funcdesc}{popen}{command\optional{, mode\optional{, bufsize}}}
292Open a pipe to or from \var{command}. The return value is an open
293file object connected to the pipe, which can be read or written
294depending on whether \var{mode} is \code{'r'} (default) or \code{'w'}.
295The \var{bufsize} argument has the same meaning as the corresponding
296argument to the built-in \function{open()} function. The exit status of
297the command (encoded in the format specified for \function{wait()}) is
298available as the return value of the \method{close()} method of the file
299object, except that when the exit status is zero (termination without
Fred Drake1319e3e2000-10-03 17:14:27 +0000300errors), \code{None} is returned.
Fred Drakec37b65e2001-11-28 07:26:15 +0000301Availability: \UNIX, Windows.
Fred Drakec71c23e2000-10-04 13:57:27 +0000302
303\versionchanged[This function worked unreliably under Windows in
304 earlier versions of Python. This was due to the use of the
305 \cfunction{_popen()} function from the libraries provided with
306 Windows. Newer versions of Python do not use the broken
307 implementation from the Windows libraries]{2.0}
Fred Drake215fe2f1999-02-02 19:02:35 +0000308\end{funcdesc}
309
Fred Drake18f7a451999-12-09 22:11:43 +0000310\begin{funcdesc}{tmpfile}{}
311Return a new file object opened in update mode (\samp{w+}). The file
312has no directory entries associated with it and will be automatically
313deleted once there are no file descriptors for the file.
Fred Drakec37b65e2001-11-28 07:26:15 +0000314Availability: \UNIX, Windows.
Fred Drake18f7a451999-12-09 22:11:43 +0000315\end{funcdesc}
Fred Drake215fe2f1999-02-02 19:02:35 +0000316
317
Fred Drake8a9db992000-09-28 20:27:51 +0000318For each of these \function{popen()} variants, if \var{bufsize} is
319specified, it specifies the buffer size for the I/O pipes.
320\var{mode}, if provided, should be the string \code{'b'} or
321\code{'t'}; on Windows this is needed to determine whether the file
322objects should be opened in binary or text mode. The default value
323for \var{mode} is \code{'t'}.
324
Fred Drake098d7fa2001-09-11 19:56:51 +0000325These methods do not make it possible to retrieve the return code from
326the child processes. The only way to control the input and output
327streams and also retrieve the return codes is to use the
328\class{Popen3} and \class{Popen4} classes from the \refmodule{popen2}
329module; these are only available on \UNIX.
330
Fred Drake046f4d82001-06-11 15:21:48 +0000331\begin{funcdesc}{popen2}{cmd\optional{, mode\optional{, bufsize}}}
Fred Drake8a9db992000-09-28 20:27:51 +0000332Executes \var{cmd} as a sub-process. Returns the file objects
333\code{(\var{child_stdin}, \var{child_stdout})}.
Fred Drakec37b65e2001-11-28 07:26:15 +0000334Availability: \UNIX, Windows.
Fred Drake8a9db992000-09-28 20:27:51 +0000335\versionadded{2.0}
336\end{funcdesc}
337
Fred Drake046f4d82001-06-11 15:21:48 +0000338\begin{funcdesc}{popen3}{cmd\optional{, mode\optional{, bufsize}}}
Fred Drake8a9db992000-09-28 20:27:51 +0000339Executes \var{cmd} as a sub-process. Returns the file objects
340\code{(\var{child_stdin}, \var{child_stdout}, \var{child_stderr})}.
Fred Drakec37b65e2001-11-28 07:26:15 +0000341Availability: \UNIX, Windows.
Fred Drake8a9db992000-09-28 20:27:51 +0000342\versionadded{2.0}
343\end{funcdesc}
344
Fred Drake046f4d82001-06-11 15:21:48 +0000345\begin{funcdesc}{popen4}{cmd\optional{, mode\optional{, bufsize}}}
Fred Drake8a9db992000-09-28 20:27:51 +0000346Executes \var{cmd} as a sub-process. Returns the file objects
347\code{(\var{child_stdin}, \var{child_stdout_and_stderr})}.
Fred Drakec37b65e2001-11-28 07:26:15 +0000348Availability: \UNIX, Windows.
Fred Drake8a9db992000-09-28 20:27:51 +0000349\versionadded{2.0}
350\end{funcdesc}
351
352This functionality is also available in the \refmodule{popen2} module
353using functions of the same names, but the return values of those
354functions have a different order.
355
356
Fred Drake215fe2f1999-02-02 19:02:35 +0000357\subsection{File Descriptor Operations \label{os-fd-ops}}
358
359These functions operate on I/O streams referred to
360using file descriptors.
361
362
363\begin{funcdesc}{close}{fd}
364Close file descriptor \var{fd}.
Fred Drakec37b65e2001-11-28 07:26:15 +0000365Availability: Macintosh, \UNIX, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000366
367Note: this function is intended for low-level I/O and must be applied
368to a file descriptor as returned by \function{open()} or
369\function{pipe()}. To close a ``file object'' returned by the
370built-in function \function{open()} or by \function{popen()} or
371\function{fdopen()}, use its \method{close()} method.
372\end{funcdesc}
373
374\begin{funcdesc}{dup}{fd}
375Return a duplicate of file descriptor \var{fd}.
Fred Drakec37b65e2001-11-28 07:26:15 +0000376Availability: Macintosh, \UNIX, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000377\end{funcdesc}
378
379\begin{funcdesc}{dup2}{fd, fd2}
380Duplicate file descriptor \var{fd} to \var{fd2}, closing the latter
381first if necessary.
Fred Drakec37b65e2001-11-28 07:26:15 +0000382Availability: \UNIX, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000383\end{funcdesc}
384
Fred Drake88f6ca21999-12-15 19:39:04 +0000385\begin{funcdesc}{fpathconf}{fd, name}
Thomas Woutersf8316632000-07-16 19:01:10 +0000386Return system configuration information relevant to an open file.
Fred Drake88f6ca21999-12-15 19:39:04 +0000387\var{name} specifies the configuration value to retrieve; it may be a
388string which is the name of a defined system value; these names are
Fred Drakec37b65e2001-11-28 07:26:15 +0000389specified in a number of standards (\POSIX.1, \UNIX 95, \UNIX 98, and
Fred Drake88f6ca21999-12-15 19:39:04 +0000390others). Some platforms define additional names as well. The names
391known to the host operating system are given in the
392\code{pathconf_names} dictionary. For configuration variables not
393included in that mapping, passing an integer for \var{name} is also
394accepted.
Fred Drakec37b65e2001-11-28 07:26:15 +0000395Availability: \UNIX.
Fred Drake88f6ca21999-12-15 19:39:04 +0000396
397If \var{name} is a string and is not known, \exception{ValueError} is
398raised. If a specific value for \var{name} is not supported by the
399host system, even if it is included in \code{pathconf_names}, an
400\exception{OSError} is raised with \constant{errno.EINVAL} for the
401error number.
402\end{funcdesc}
403
Fred Drake215fe2f1999-02-02 19:02:35 +0000404\begin{funcdesc}{fstat}{fd}
405Return status for file descriptor \var{fd}, like \function{stat()}.
Fred Drakec37b65e2001-11-28 07:26:15 +0000406Availability: \UNIX, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000407\end{funcdesc}
408
409\begin{funcdesc}{fstatvfs}{fd}
410Return information about the filesystem containing the file associated
411with file descriptor \var{fd}, like \function{statvfs()}.
Fred Drakec37b65e2001-11-28 07:26:15 +0000412Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +0000413\end{funcdesc}
414
415\begin{funcdesc}{ftruncate}{fd, length}
416Truncate the file corresponding to file descriptor \var{fd},
417so that it is at most \var{length} bytes in size.
Fred Drakec37b65e2001-11-28 07:26:15 +0000418Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +0000419\end{funcdesc}
420
Skip Montanarod3725212000-07-19 17:30:58 +0000421\begin{funcdesc}{isatty}{fd}
422Return \code{1} if the file descriptor \var{fd} is open and connected to a
423tty(-like) device, else \code{0}.
Fred Drakec37b65e2001-11-28 07:26:15 +0000424Availability: \UNIX.
Skip Montanarod3725212000-07-19 17:30:58 +0000425\end{funcdesc}
426
Fred Drake215fe2f1999-02-02 19:02:35 +0000427\begin{funcdesc}{lseek}{fd, pos, how}
428Set the current position of file descriptor \var{fd} to position
429\var{pos}, modified by \var{how}: \code{0} to set the position
430relative to the beginning of the file; \code{1} to set it relative to
431the current position; \code{2} to set it relative to the end of the
432file.
Fred Drakec37b65e2001-11-28 07:26:15 +0000433Availability: Macintosh, \UNIX, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000434\end{funcdesc}
435
436\begin{funcdesc}{open}{file, flags\optional{, mode}}
437Open the file \var{file} and set various flags according to
438\var{flags} and possibly its mode according to \var{mode}.
439The default \var{mode} is \code{0777} (octal), and the current umask
440value is first masked out. Return the file descriptor for the newly
441opened file.
Fred Drakec37b65e2001-11-28 07:26:15 +0000442Availability: Macintosh, \UNIX, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000443
444For a description of the flag and mode values, see the C run-time
445documentation; flag constants (like \constant{O_RDONLY} and
446\constant{O_WRONLY}) are defined in this module too (see below).
447
448Note: this function is intended for low-level I/O. For normal usage,
449use the built-in function \function{open()}, which returns a ``file
450object'' with \method{read()} and \method{write()} methods (and many
451more).
452\end{funcdesc}
453
Fred Drakec82634c2000-06-28 17:27:48 +0000454\begin{funcdesc}{openpty}{}
455Open a new pseudo-terminal pair. Return a pair of file descriptors
456\code{(\var{master}, \var{slave})} for the pty and the tty,
457respectively. For a (slightly) more portable approach, use the
458\refmodule{pty}\refstmodindex{pty} module.
Fred Drakec37b65e2001-11-28 07:26:15 +0000459Availability: Some flavors of \UNIX.
Fred Drakec82634c2000-06-28 17:27:48 +0000460\end{funcdesc}
461
Fred Drake215fe2f1999-02-02 19:02:35 +0000462\begin{funcdesc}{pipe}{}
463Create a pipe. Return a pair of file descriptors \code{(\var{r},
464\var{w})} usable for reading and writing, respectively.
Fred Drakec37b65e2001-11-28 07:26:15 +0000465Availability: \UNIX, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000466\end{funcdesc}
467
468\begin{funcdesc}{read}{fd, n}
469Read at most \var{n} bytes from file descriptor \var{fd}.
470Return a string containing the bytes read.
Fred Drakec37b65e2001-11-28 07:26:15 +0000471Availability: Macintosh, \UNIX, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000472
473Note: this function is intended for low-level I/O and must be applied
474to a file descriptor as returned by \function{open()} or
475\function{pipe()}. To read a ``file object'' returned by the
476built-in function \function{open()} or by \function{popen()} or
477\function{fdopen()}, or \code{sys.stdin}, use its
478\method{read()} or \method{readline()} methods.
479\end{funcdesc}
480
481\begin{funcdesc}{tcgetpgrp}{fd}
482Return the process group associated with the terminal given by
483\var{fd} (an open file descriptor as returned by \function{open()}).
Fred Drakec37b65e2001-11-28 07:26:15 +0000484Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +0000485\end{funcdesc}
486
487\begin{funcdesc}{tcsetpgrp}{fd, pg}
488Set the process group associated with the terminal given by
489\var{fd} (an open file descriptor as returned by \function{open()})
490to \var{pg}.
Fred Drakec37b65e2001-11-28 07:26:15 +0000491Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +0000492\end{funcdesc}
493
494\begin{funcdesc}{ttyname}{fd}
495Return a string which specifies the terminal device associated with
496file-descriptor \var{fd}. If \var{fd} is not associated with a terminal
497device, an exception is raised.
Fred Drakec37b65e2001-11-28 07:26:15 +0000498Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +0000499\end{funcdesc}
500
501\begin{funcdesc}{write}{fd, str}
502Write the string \var{str} to file descriptor \var{fd}.
503Return the number of bytes actually written.
Fred Drakec37b65e2001-11-28 07:26:15 +0000504Availability: Macintosh, \UNIX, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000505
506Note: this function is intended for low-level I/O and must be applied
507to a file descriptor as returned by \function{open()} or
508\function{pipe()}. To write a ``file object'' returned by the
509built-in function \function{open()} or by \function{popen()} or
510\function{fdopen()}, or \code{sys.stdout} or \code{sys.stderr}, use
511its \method{write()} method.
512\end{funcdesc}
513
514
515The following data items are available for use in constructing the
516\var{flags} parameter to the \function{open()} function.
517
518\begin{datadesc}{O_RDONLY}
519\dataline{O_WRONLY}
520\dataline{O_RDWR}
521\dataline{O_NDELAY}
522\dataline{O_NONBLOCK}
523\dataline{O_APPEND}
524\dataline{O_DSYNC}
525\dataline{O_RSYNC}
526\dataline{O_SYNC}
527\dataline{O_NOCTTY}
528\dataline{O_CREAT}
529\dataline{O_EXCL}
530\dataline{O_TRUNC}
531Options for the \var{flag} argument to the \function{open()} function.
532These can be bit-wise OR'd together.
Fred Drakec37b65e2001-11-28 07:26:15 +0000533Availability: Macintosh, \UNIX, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000534\end{datadesc}
535
Fred Drake3ac977e2000-08-11 20:19:51 +0000536\begin{datadesc}{O_BINARY}
537Option for the \var{flag} argument to the \function{open()} function.
538This can be bit-wise OR'd together with those listed above.
539Availability: Macintosh, Windows.
540% XXX need to check on the availability of this one.
541\end{datadesc}
542
Fred Drake215fe2f1999-02-02 19:02:35 +0000543
544\subsection{Files and Directories \label{os-file-dir}}
545
546\begin{funcdesc}{access}{path, mode}
Fred Drake38e5d272000-04-03 20:13:55 +0000547Check read/write/execute permissions for this process or existence of
548file \var{path}. \var{mode} should be \constant{F_OK} to test the
549existence of \var{path}, or it can be the inclusive OR of one or more
550of \constant{R_OK}, \constant{W_OK}, and \constant{X_OK} to test
551permissions. Return \code{1} if access is allowed, \code{0} if not.
552See the \UNIX{} man page \manpage{access}{2} for more information.
Fred Drakec37b65e2001-11-28 07:26:15 +0000553Availability: \UNIX, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000554\end{funcdesc}
555
Fred Drake38e5d272000-04-03 20:13:55 +0000556\begin{datadesc}{F_OK}
557 Value to pass as the \var{mode} parameter of \function{access()} to
558 test the existence of \var{path}.
559\end{datadesc}
560
561\begin{datadesc}{R_OK}
562 Value to include in the \var{mode} parameter of \function{access()}
563 to test the readability of \var{path}.
564\end{datadesc}
565
566\begin{datadesc}{W_OK}
567 Value to include in the \var{mode} parameter of \function{access()}
568 to test the writability of \var{path}.
569\end{datadesc}
570
571\begin{datadesc}{X_OK}
572 Value to include in the \var{mode} parameter of \function{access()}
573 to determine if \var{path} can be executed.
574\end{datadesc}
575
Fred Drake6db897c1999-07-12 16:49:30 +0000576\begin{funcdesc}{chdir}{path}
577\index{directory!changing}
578Change the current working directory to \var{path}.
Fred Drakec37b65e2001-11-28 07:26:15 +0000579Availability: Macintosh, \UNIX, Windows.
Fred Drake6db897c1999-07-12 16:49:30 +0000580\end{funcdesc}
581
582\begin{funcdesc}{getcwd}{}
583Return a string representing the current working directory.
Fred Drakec37b65e2001-11-28 07:26:15 +0000584Availability: Macintosh, \UNIX, Windows.
Fred Drake6db897c1999-07-12 16:49:30 +0000585\end{funcdesc}
586
Martin v. Löwis244edc82001-10-04 22:44:26 +0000587\begin{funcdesc}{chroot}{path}
588Change the root directory of the current process to \var{path}.
Fred Drakec37b65e2001-11-28 07:26:15 +0000589Availability: \UNIX.
Martin v. Löwis244edc82001-10-04 22:44:26 +0000590\versionadded{2.2}
591\end{funcdesc}
592
Fred Drake215fe2f1999-02-02 19:02:35 +0000593\begin{funcdesc}{chmod}{path, mode}
594Change the mode of \var{path} to the numeric \var{mode}.
Fred Drakec37b65e2001-11-28 07:26:15 +0000595Availability: \UNIX, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000596\end{funcdesc}
597
598\begin{funcdesc}{chown}{path, uid, gid}
599Change the owner and group id of \var{path} to the numeric \var{uid}
600and \var{gid}.
Fred Drakec37b65e2001-11-28 07:26:15 +0000601Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +0000602\end{funcdesc}
603
604\begin{funcdesc}{link}{src, dst}
605Create a hard link pointing to \var{src} named \var{dst}.
Fred Drakec37b65e2001-11-28 07:26:15 +0000606Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +0000607\end{funcdesc}
608
609\begin{funcdesc}{listdir}{path}
610Return a list containing the names of the entries in the directory.
611The list is in arbitrary order. It does not include the special
612entries \code{'.'} and \code{'..'} even if they are present in the
613directory.
Fred Drakec37b65e2001-11-28 07:26:15 +0000614Availability: Macintosh, \UNIX, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000615\end{funcdesc}
616
617\begin{funcdesc}{lstat}{path}
618Like \function{stat()}, but do not follow symbolic links.
Fred Drakec37b65e2001-11-28 07:26:15 +0000619Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +0000620\end{funcdesc}
621
622\begin{funcdesc}{mkfifo}{path\optional{, mode}}
623Create a FIFO (a named pipe) named \var{path} with numeric mode
624\var{mode}. The default \var{mode} is \code{0666} (octal). The current
625umask value is first masked out from the mode.
Fred Drakec37b65e2001-11-28 07:26:15 +0000626Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +0000627
628FIFOs are pipes that can be accessed like regular files. FIFOs exist
629until they are deleted (for example with \function{os.unlink()}).
630Generally, FIFOs are used as rendezvous between ``client'' and
631``server'' type processes: the server opens the FIFO for reading, and
632the client opens it for writing. Note that \function{mkfifo()}
633doesn't open the FIFO --- it just creates the rendezvous point.
634\end{funcdesc}
635
636\begin{funcdesc}{mkdir}{path\optional{, mode}}
637Create a directory named \var{path} with numeric mode \var{mode}.
638The default \var{mode} is \code{0777} (octal). On some systems,
639\var{mode} is ignored. Where it is used, the current umask value is
640first masked out.
Fred Drakec37b65e2001-11-28 07:26:15 +0000641Availability: Macintosh, \UNIX, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000642\end{funcdesc}
643
644\begin{funcdesc}{makedirs}{path\optional{, mode}}
645\index{directory!creating}
646Recursive directory creation function. Like \function{mkdir()},
647but makes all intermediate-level directories needed to contain the
648leaf directory. Throws an \exception{error} exception if the leaf
649directory already exists or cannot be created. The default \var{mode}
Fred Drakebbf7a402001-09-28 16:14:18 +0000650is \code{0777} (octal). This function does not properly handle UNC
651paths (only relevant on Windows systems).
Fred Drake215fe2f1999-02-02 19:02:35 +0000652\versionadded{1.5.2}
653\end{funcdesc}
654
Fred Drake88f6ca21999-12-15 19:39:04 +0000655\begin{funcdesc}{pathconf}{path, name}
Thomas Woutersf8316632000-07-16 19:01:10 +0000656Return system configuration information relevant to a named file.
Fred Drake88f6ca21999-12-15 19:39:04 +0000657\var{name} specifies the configuration value to retrieve; it may be a
658string which is the name of a defined system value; these names are
Fred Drake8ee679f2001-07-14 02:50:55 +0000659specified in a number of standards (\POSIX.1, \UNIX 95, \UNIX 98, and
Fred Drake88f6ca21999-12-15 19:39:04 +0000660others). Some platforms define additional names as well. The names
661known to the host operating system are given in the
662\code{pathconf_names} dictionary. For configuration variables not
663included in that mapping, passing an integer for \var{name} is also
664accepted.
Fred Drakec37b65e2001-11-28 07:26:15 +0000665Availability: \UNIX.
Fred Drake88f6ca21999-12-15 19:39:04 +0000666
667If \var{name} is a string and is not known, \exception{ValueError} is
668raised. If a specific value for \var{name} is not supported by the
669host system, even if it is included in \code{pathconf_names}, an
670\exception{OSError} is raised with \constant{errno.EINVAL} for the
671error number.
672\end{funcdesc}
673
674\begin{datadesc}{pathconf_names}
675Dictionary mapping names accepted by \function{pathconf()} and
676\function{fpathconf()} to the integer values defined for those names
677by the host operating system. This can be used to determine the set
678of names known to the system.
679Availability: \UNIX.
680\end{datadesc}
681
Fred Drake215fe2f1999-02-02 19:02:35 +0000682\begin{funcdesc}{readlink}{path}
683Return a string representing the path to which the symbolic link
Fred Drakedc9e7e42001-05-29 18:13:06 +0000684points. The result may be either an absolute or relative pathname; if
685it is relative, it may be converted to an absolute pathname using
686\code{os.path.join(os.path.dirname(\var{path}), \var{result})}.
Fred Drakec37b65e2001-11-28 07:26:15 +0000687Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +0000688\end{funcdesc}
689
690\begin{funcdesc}{remove}{path}
Fred Drakedc9e7e42001-05-29 18:13:06 +0000691Remove the file \var{path}. If \var{path} is a directory,
692\exception{OSError} is raised; see \function{rmdir()} below to remove
693a directory. This is identical to the \function{unlink()} function
694documented below. On Windows, attempting to remove a file that is in
695use causes an exception to be raised; on \UNIX, the directory entry is
696removed but the storage allocated to the file is not made available
697until the original file is no longer in use.
Fred Drakec37b65e2001-11-28 07:26:15 +0000698Availability: Macintosh, \UNIX, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000699\end{funcdesc}
700
701\begin{funcdesc}{removedirs}{path}
702\index{directory!deleting}
703Recursive directory removal function. Works like
704\function{rmdir()} except that, if the leaf directory is
705successfully removed, directories corresponding to rightmost path
706segments will be pruned way until either the whole path is consumed or
707an error is raised (which is ignored, because it generally means that
708a parent directory is not empty). Throws an \exception{error}
709exception if the leaf directory could not be successfully removed.
710\versionadded{1.5.2}
711\end{funcdesc}
712
713\begin{funcdesc}{rename}{src, dst}
Fred Drakedc9e7e42001-05-29 18:13:06 +0000714Rename the file or directory \var{src} to \var{dst}. If \var{dst} is
715a directory, \exception{OSError} will be raised. On \UNIX, if
716\var{dst} exists and is a file, it will be removed silently if the
717user has permission. The operation may fail on some \UNIX{} flavors
Skip Montanarob9d973d2001-06-04 15:31:17 +0000718if \var{src} and \var{dst} are on different filesystems. If
Fred Drakedc9e7e42001-05-29 18:13:06 +0000719successful, the renaming will be an atomic operation (this is a
720\POSIX{} requirement). On Windows, if \var{dst} already exists,
721\exception{OSError} will be raised even if it is a file; there may be
722no way to implement an atomic rename when \var{dst} names an existing
723file.
Fred Drakec37b65e2001-11-28 07:26:15 +0000724Availability: Macintosh, \UNIX, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000725\end{funcdesc}
726
727\begin{funcdesc}{renames}{old, new}
728Recursive directory or file renaming function.
729Works like \function{rename()}, except creation of any intermediate
730directories needed to make the new pathname good is attempted first.
731After the rename, directories corresponding to rightmost path segments
732of the old name will be pruned away using \function{removedirs()}.
733
734Note: this function can fail with the new directory structure made if
735you lack permissions needed to remove the leaf directory or file.
736\versionadded{1.5.2}
737\end{funcdesc}
738
739\begin{funcdesc}{rmdir}{path}
740Remove the directory \var{path}.
Fred Drakec37b65e2001-11-28 07:26:15 +0000741Availability: Macintosh, \UNIX, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000742\end{funcdesc}
743
744\begin{funcdesc}{stat}{path}
745Perform a \cfunction{stat()} system call on the given path. The
Fred Drake6995bb62001-11-29 20:48:44 +0000746return value is an object whose attributes correspond to the members of
747the \ctype{stat} structure, namely:
748\member{st_mode} (protection bits),
749\member{st_ino} (inode number),
750\member{st_dev} (device),
751\member{st_nlink} (number of hard links,
752\member{st_uid} (user ID of owner),
753\member{st_gid} (group ID of owner),
754\member{st_size} (size of file, in bytes),
755\member{st_atime} (time of most recent access),
756\member{st_mtime} (time of most recent content modification),
757\member{st_ctime}
758(time of most recent content modification or metadata change).
759
760On some Unix systems (such as Linux), the following attributes may
761also be available:
762\member{st_blocks} (number of blocks allocated for file),
763\member{st_blksize} (filesystem blocksize),
764\member{st_rdev} (type of device if an inode device).
765
766On Mac OS systems, the following attributes may also be available:
767\member{st_rsize},
768\member{st_creator},
769\member{st_type}.
770
771On RISCOS systems, the following attributes are also available:
772\member{st_ftype} (file type),
773\member{st_attrs} (attributes),
774\member{st_obtype} (object type).
775
776For backward compatibility, the return value of \function{stat()} is
777also accessible as a tuple of at least 10 integers giving the most
778important (and portable) members of the \ctype{stat} structure, in the
Fred Drake215fe2f1999-02-02 19:02:35 +0000779order
Fred Drake6995bb62001-11-29 20:48:44 +0000780\member{st_mode},
781\member{st_ino},
782\member{st_dev},
783\member{st_nlink},
784\member{st_uid},
785\member{st_gid},
786\member{st_size},
787\member{st_atime},
788\member{st_mtime},
789\member{st_ctime}.
Fred Drake21c9df72000-10-14 05:46:11 +0000790More items may be added at the end by some implementations. Note that
Fred Drake8ee679f2001-07-14 02:50:55 +0000791on the Mac OS, the time values are floating point values, like all
792time values on the Mac OS.
Fred Drake6995bb62001-11-29 20:48:44 +0000793The standard module \refmodule{stat}\refstmodindex{stat} defines
794functions and constants that are useful for extracting information
795from a \ctype{stat} structure.
Fred Drake8ee679f2001-07-14 02:50:55 +0000796(On Windows, some items are filled with dummy values.)
Fred Drakec37b65e2001-11-28 07:26:15 +0000797Availability: Macintosh, \UNIX, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000798
Fred Drake6995bb62001-11-29 20:48:44 +0000799\versionchanged
800[Added access to values as attributes of the returned object]{2.2}
Fred Drake215fe2f1999-02-02 19:02:35 +0000801\end{funcdesc}
802
803\begin{funcdesc}{statvfs}{path}
804Perform a \cfunction{statvfs()} system call on the given path. The
Fred Drake6995bb62001-11-29 20:48:44 +0000805return value is an object whose attributes describe the filesystem on
806the given path, and correspond to the members of the
807\ctype{statvfs} structure, namely:
808\member{f_frsize},
809\member{f_blocks},
810\member{f_bfree},
811\member{f_bavail},
812\member{f_files},
813\member{f_ffree},
814\member{f_favail},
815\member{f_flag},
816\member{f_namemax}.
Fred Drakec37b65e2001-11-28 07:26:15 +0000817Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +0000818
Fred Drake6995bb62001-11-29 20:48:44 +0000819For backward compatibility, the return value is also accessible as a
820tuple whose values correspond to the attributes, in the order given above.
821The standard module \refmodule{statvfs}\refstmodindex{statvfs}
Fred Drake215fe2f1999-02-02 19:02:35 +0000822defines constants that are useful for extracting information
Fred Drake6995bb62001-11-29 20:48:44 +0000823from a \ctype{statvfs} structure when accessing it as a sequence; this
824remains useful when writing code that needs to work with versions of
825Python that don't support accessing the fields as attributes.
826
827\versionchanged
828[Added access to values as attributes of the returned object]{2.2}
Fred Drake215fe2f1999-02-02 19:02:35 +0000829\end{funcdesc}
830
831\begin{funcdesc}{symlink}{src, dst}
832Create a symbolic link pointing to \var{src} named \var{dst}.
Fred Drakec37b65e2001-11-28 07:26:15 +0000833Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +0000834\end{funcdesc}
835
Fred Drake18f7a451999-12-09 22:11:43 +0000836\begin{funcdesc}{tempnam}{\optional{dir\optional{, prefix}}}
837Return a unique path name that is reasonable for creating a temporary
838file. This will be an absolute path that names a potential directory
839entry in the directory \var{dir} or a common location for temporary
840files if \var{dir} is omitted or \code{None}. If given and not
841\code{None}, \var{prefix} is used to provide a short prefix to the
842filename. Applications are responsible for properly creating and
843managing files created using paths returned by \function{tempnam()};
844no automatic cleanup is provided.
Fred Drake938a8d72001-10-09 18:07:04 +0000845\warning{Use of \function{tempnam()} is vulnerable to symlink attacks;
846consider using \function{tmpfile()} instead.}
Fred Drakeefaef132001-07-17 20:39:18 +0000847Availability: \UNIX, Windows.
Fred Drake18f7a451999-12-09 22:11:43 +0000848\end{funcdesc}
849
850\begin{funcdesc}{tmpnam}{}
851Return a unique path name that is reasonable for creating a temporary
852file. This will be an absolute path that names a potential directory
853entry in a common location for temporary files. Applications are
854responsible for properly creating and managing files created using
855paths returned by \function{tmpnam()}; no automatic cleanup is
856provided.
Fred Drake938a8d72001-10-09 18:07:04 +0000857\warning{Use of \function{tmpnam()} is vulnerable to symlink attacks;
858consider using \function{tmpfile()} instead.}
Fred Drakeefaef132001-07-17 20:39:18 +0000859Availability: \UNIX, Windows.
Fred Drake18f7a451999-12-09 22:11:43 +0000860\end{funcdesc}
861
862\begin{datadesc}{TMP_MAX}
863The maximum number of unique names that \function{tmpnam()} will
864generate before reusing names.
865\end{datadesc}
866
Fred Drake215fe2f1999-02-02 19:02:35 +0000867\begin{funcdesc}{unlink}{path}
868Remove the file \var{path}. This is the same function as
869\function{remove()}; the \function{unlink()} name is its traditional
870\UNIX{} name.
Fred Drakec37b65e2001-11-28 07:26:15 +0000871Availability: Macintosh, \UNIX, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000872\end{funcdesc}
873
Barry Warsaw93a8eac2000-05-01 16:18:22 +0000874\begin{funcdesc}{utime}{path, times}
875Set the access and modified times of the file specified by \var{path}.
876If \var{times} is \code{None}, then the file's access and modified
877times are set to the current time. Otherwise, \var{times} must be a
Fred Drakee06d0252000-05-02 17:29:35 +00008782-tuple of numbers, of the form \code{(\var{atime}, \var{mtime})}
879which is used to set the access and modified times, respectively.
Fred Drake4a152632000-10-19 05:33:46 +0000880\versionchanged[Added support for \code{None} for \var{times}]{2.0}
Fred Drakec37b65e2001-11-28 07:26:15 +0000881Availability: Macintosh, \UNIX, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000882\end{funcdesc}
883
884
885\subsection{Process Management \label{os-process}}
886
Fred Drake18f7a451999-12-09 22:11:43 +0000887These functions may be used to create and manage processes.
Fred Drake215fe2f1999-02-02 19:02:35 +0000888
Fred Drake7be31152000-09-23 05:22:07 +0000889The various \function{exec*()} functions take a list of arguments for
890the new program loaded into the process. In each case, the first of
891these arguments is passed to the new program as its own name rather
892than as an argument a user may have typed on a command line. For the
893C programmer, this is the \code{argv[0]} passed to a program's
894\cfunction{main()}. For example, \samp{os.execv('/bin/echo', ['foo',
895'bar'])} will only print \samp{bar} on standard output; \samp{foo}
896will seem to be ignored.
897
Fred Drake215fe2f1999-02-02 19:02:35 +0000898
Fred Drake18f7a451999-12-09 22:11:43 +0000899\begin{funcdesc}{abort}{}
900Generate a \constant{SIGABRT} signal to the current process. On
901\UNIX, the default behavior is to produce a core dump; on Windows, the
902process immediately returns an exit code of \code{3}. Be aware that
903programs which use \function{signal.signal()} to register a handler
904for \constant{SIGABRT} will behave differently.
905Availability: \UNIX, Windows.
906\end{funcdesc}
907
Fred Drakedb7287c2001-10-18 18:58:30 +0000908\begin{funcdesc}{execl}{path, arg0, arg1, \moreargs}
909\funcline{execle}{path, arg0, arg1, \moreargs, env}
910\funcline{execlp}{file, arg0, arg1, \moreargs}
911\funcline{execlpe}{file, arg0, arg1, \moreargs, env}
912\funcline{execv}{path, args}
913\funcline{execve}{path, args, env}
914\funcline{execvp}{file, args}
915\funcline{execvpe}{file, args, env}
916These functions all execute a new program, replacing the current
917process; they do not return. On \UNIX, the new executable is loaded
918into the current process, and will have the same process ID as the
919caller. Errors will be reported as \exception{OSError} exceptions.
Fred Drake215fe2f1999-02-02 19:02:35 +0000920
Fred Drakedb7287c2001-10-18 18:58:30 +0000921The \character{l} and \character{v} variants of the
922\function{exec*()} functions differ in how command-line arguments are
923passed. The \character{l} variants are perhaps the easiest to work
924with if the number of parameters is fixed when the code is written;
925the individual parameters simply become additional parameters to the
926\function{execl*()} functions. The \character{v} variants are good
927when the number of parameters is variable, with the arguments being
928passed in a list or tuple as the \var{args} parameter. In either
929case, the arguments to the child process must start with the name of
930the command being run.
Fred Drake215fe2f1999-02-02 19:02:35 +0000931
Fred Drakedb7287c2001-10-18 18:58:30 +0000932The variants which include a \character{p} near the end
933(\function{execlp()}, \function{execlpe()}, \function{execvp()},
934and \function{execvpe()}) will use the \envvar{PATH} environment
935variable to locate the program \var{file}. When the environment is
936being replaced (using one of the \function{exec*e()} variants,
937discussed in the next paragraph), the
938new environment is used as the source of the \envvar{PATH} variable.
939The other variants, \function{execl()}, \function{execle()},
940\function{execv()}, and \function{execve()}, will not use the
941\envvar{PATH} variable to locate the executable; \var{path} must
942contain an appropriate absolute or relative path.
Fred Drake215fe2f1999-02-02 19:02:35 +0000943
Fred Drakedb7287c2001-10-18 18:58:30 +0000944For \function{execle()}, \function{execlpe()}, \function{execve()},
945and \function{execvpe()} (note that these all end in \character{e}),
946the \var{env} parameter must be a mapping which is used to define the
947environment variables for the new process; the \function{execl()},
948\function{execlp()}, \function{execv()}, and \function{execvp()}
949all cause the new process to inherit the environment of the current
950process.
951Availability: \UNIX, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000952\end{funcdesc}
953
954\begin{funcdesc}{_exit}{n}
955Exit to the system with status \var{n}, without calling cleanup
956handlers, flushing stdio buffers, etc.
Fred Drakec37b65e2001-11-28 07:26:15 +0000957Availability: \UNIX, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000958
959Note: the standard way to exit is \code{sys.exit(\var{n})}.
960\function{_exit()} should normally only be used in the child process
961after a \function{fork()}.
962\end{funcdesc}
963
964\begin{funcdesc}{fork}{}
965Fork a child process. Return \code{0} in the child, the child's
966process id in the parent.
Fred Drakec37b65e2001-11-28 07:26:15 +0000967Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +0000968\end{funcdesc}
969
Fred Drakec82634c2000-06-28 17:27:48 +0000970\begin{funcdesc}{forkpty}{}
971Fork a child process, using a new pseudo-terminal as the child's
972controlling terminal. Return a pair of \code{(\var{pid}, \var{fd})},
973where \var{pid} is \code{0} in the child, the new child's process id
Fred Drake6995bb62001-11-29 20:48:44 +0000974in the parent, and \var{fd} is the file descriptor of the master end
Fred Drakec82634c2000-06-28 17:27:48 +0000975of the pseudo-terminal. For a more portable approach, use the
976\refmodule{pty} module.
Fred Drakec37b65e2001-11-28 07:26:15 +0000977Availability: Some flavors of \UNIX.
Fred Drakec82634c2000-06-28 17:27:48 +0000978\end{funcdesc}
979
Fred Drake215fe2f1999-02-02 19:02:35 +0000980\begin{funcdesc}{kill}{pid, sig}
981\index{process!killing}
982\index{process!signalling}
983Kill the process \var{pid} with signal \var{sig}.
Fred Drakec37b65e2001-11-28 07:26:15 +0000984Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +0000985\end{funcdesc}
986
987\begin{funcdesc}{nice}{increment}
988Add \var{increment} to the process's ``niceness''. Return the new
989niceness.
Fred Drakec37b65e2001-11-28 07:26:15 +0000990Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +0000991\end{funcdesc}
992
993\begin{funcdesc}{plock}{op}
994Lock program segments into memory. The value of \var{op}
995(defined in \code{<sys/lock.h>}) determines which segments are locked.
Fred Drakec37b65e2001-11-28 07:26:15 +0000996Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +0000997\end{funcdesc}
998
Fred Drake046f4d82001-06-11 15:21:48 +0000999\begin{funcdescni}{popen}{\unspecified}
1000\funclineni{popen2}{\unspecified}
1001\funclineni{popen3}{\unspecified}
1002\funclineni{popen4}{\unspecified}
1003Run child processes, returning opened pipes for communications. These
1004functions are described in section \ref{os-newstreams}.
1005\end{funcdescni}
1006
Fred Drake739282d2001-08-16 21:21:28 +00001007\begin{funcdesc}{spawnl}{mode, path, \moreargs}
1008\funcline{spawnle}{mode, path, \moreargs, env}
Fred Drakedb7287c2001-10-18 18:58:30 +00001009\funcline{spawnlp}{mode, file, \moreargs}
1010\funcline{spawnlpe}{mode, file, \moreargs, env}
Fred Drake739282d2001-08-16 21:21:28 +00001011\funcline{spawnv}{mode, path, args}
1012\funcline{spawnve}{mode, path, args, env}
Fred Drakedb7287c2001-10-18 18:58:30 +00001013\funcline{spawnvp}{mode, file, args}
1014\funcline{spawnvpe}{mode, file, args, env}
Fred Drake739282d2001-08-16 21:21:28 +00001015Execute the program \var{path} in a new process. If \var{mode} is
1016\constant{P_NOWAIT}, this function returns the process ID of the new
1017process; it \var{mode} is \constant{P_WAIT}, returns the process's
1018exit code if it exits normally, or \code{-\var{signal}}, where
1019\var{signal} is the signal that killed the process.
Fred Drake215fe2f1999-02-02 19:02:35 +00001020
Fred Drake739282d2001-08-16 21:21:28 +00001021The \character{l} and \character{v} variants of the
1022\function{spawn*()} functions differ in how command-line arguments are
1023passed. The \character{l} variants are perhaps the easiest to work
1024with if the number of parameters is fixed when the code is written;
1025the individual parameters simply become additional parameters to the
1026\function{spawnl*()} functions. The \character{v} variants are good
1027when the number of parameters is variable, with the arguments being
1028passed in a list or tuple as the \var{args} parameter. In either
1029case, the arguments to the child process must start with the name of
1030the command being run.
1031
Fred Drakedb7287c2001-10-18 18:58:30 +00001032The variants which include a second \character{p} near the end
1033(\function{spawnlp()}, \function{spawnlpe()}, \function{spawnvp()},
1034and \function{spawnvpe()}) will use the \envvar{PATH} environment
1035variable to locate the program \var{file}. When the environment is
1036being replaced (using one of the \function{spawn*e()} variants,
1037discussed in the next paragraph), the new environment is used as the
1038source of the \envvar{PATH} variable. The other variants,
1039\function{spawnl()}, \function{spawnle()}, \function{spawnv()}, and
1040\function{spawnve()}, will not use the \envvar{PATH} variable to
1041locate the executable; \var{path} must contain an appropriate absolute
1042or relative path.
1043
1044For \function{spawnle()}, \function{spawnlpe()}, \function{spawnve()},
1045and \function{spawnvpe()} (note that these all end in \character{e}),
1046the \var{env} parameter must be a mapping which is used to define the
1047environment variables for the new process; the \function{spawnl()},
1048\function{spawnlp()}, \function{spawnv()}, and \function{spawnvp()}
1049all cause the new process to inherit the environment of the current
1050process.
1051
Fred Drake739282d2001-08-16 21:21:28 +00001052As an example, the following calls to \function{spawnlp()} and
1053\function{spawnvpe()} are equivalent:
1054
1055\begin{verbatim}
1056import os
1057os.spawnlp(os.P_WAIT, 'cp', 'cp', 'index.html', '/dev/null')
1058
1059L = ['cp', 'index.html', '/dev/null']
1060os.spawnvpe(os.P_WAIT, 'cp', L, os.environ)
1061\end{verbatim}
1062
Fred Drakedb7287c2001-10-18 18:58:30 +00001063Availability: \UNIX, Windows. \function{spawnvp()} and
1064\function{spawnvpe()} are not available on Windows.
Fred Drake0b9bc202001-06-11 18:25:34 +00001065\versionadded{1.6}
Fred Drake215fe2f1999-02-02 19:02:35 +00001066\end{funcdesc}
1067
Fred Drake938a8d72001-10-09 18:07:04 +00001068\begin{datadesc}{P_NOWAIT}
Fred Drake9329e5e1999-02-16 19:40:19 +00001069\dataline{P_NOWAITO}
Fred Drake938a8d72001-10-09 18:07:04 +00001070Possible values for the \var{mode} parameter to the \function{spawn*()}
1071family of functions. If either of these values is given, the
1072\function{spawn*()} functions will return as soon as the new process
1073has been created, with the process ID as the return value.
Fred Drakec37b65e2001-11-28 07:26:15 +00001074Availability: \UNIX, Windows.
Fred Drake0b9bc202001-06-11 18:25:34 +00001075\versionadded{1.6}
Fred Drake15861b22000-02-29 05:19:38 +00001076\end{datadesc}
1077
Fred Drake938a8d72001-10-09 18:07:04 +00001078\begin{datadesc}{P_WAIT}
1079Possible value for the \var{mode} parameter to the \function{spawn*()}
1080family of functions. If this is given as \var{mode}, the
1081\function{spawn*()} functions will not return until the new process
1082has run to completion and will return the exit code of the process the
1083run is successful, or \code{-\var{signal}} if a signal kills the
1084process.
Fred Drakec37b65e2001-11-28 07:26:15 +00001085Availability: \UNIX, Windows.
Fred Drake938a8d72001-10-09 18:07:04 +00001086\versionadded{1.6}
1087\end{datadesc}
1088
1089\begin{datadesc}{P_DETACH}
1090\dataline{P_OVERLAY}
1091Possible values for the \var{mode} parameter to the
1092\function{spawn*()} family of functions. These are less portable than
1093those listed above.
1094\constant{P_DETACH} is similar to \constant{P_NOWAIT}, but the new
1095process is detached from the console of the calling process.
1096If \constant{P_OVERLAY} is used, the current process will be replaced;
1097the \function{spawn*()} function will not return.
Fred Drake215fe2f1999-02-02 19:02:35 +00001098Availability: Windows.
Fred Drake0b9bc202001-06-11 18:25:34 +00001099\versionadded{1.6}
Fred Drake215fe2f1999-02-02 19:02:35 +00001100\end{datadesc}
1101
Fred Drake4ce4f2e2000-09-29 04:15:19 +00001102\begin{funcdesc}{startfile}{path}
1103Start a file with its associated application. This acts like
1104double-clicking the file in Windows Explorer, or giving the file name
Fred Drake8ee679f2001-07-14 02:50:55 +00001105as an argument to the \program{start} command from the interactive
1106command shell: the file is opened with whatever application (if any)
1107its extension is associated.
Fred Drake4ce4f2e2000-09-29 04:15:19 +00001108
1109\function{startfile()} returns as soon as the associated application
1110is launched. There is no option to wait for the application to close,
1111and no way to retrieve the application's exit status. The \var{path}
1112parameter is relative to the current directory. If you want to use an
1113absolute path, make sure the first character is not a slash
1114(\character{/}); the underlying Win32 \cfunction{ShellExecute()}
Fred Drake8a2adcf2001-07-23 19:20:56 +00001115function doesn't work if it is. Use the \function{os.path.normpath()}
Fred Drake4ce4f2e2000-09-29 04:15:19 +00001116function to ensure that the path is properly encoded for Win32.
1117Availability: Windows.
1118\versionadded{2.0}
1119\end{funcdesc}
1120
Fred Drake215fe2f1999-02-02 19:02:35 +00001121\begin{funcdesc}{system}{command}
1122Execute the command (a string) in a subshell. This is implemented by
1123calling the Standard C function \cfunction{system()}, and has the
Fred Drakeec6baaf1999-04-21 18:13:31 +00001124same limitations. Changes to \code{posix.environ}, \code{sys.stdin},
Fred Drake215fe2f1999-02-02 19:02:35 +00001125etc.\ are not reflected in the environment of the executed command.
1126The return value is the exit status of the process encoded in the
Fred Drake7a621281999-06-10 15:07:05 +00001127format specified for \function{wait()}, except on Windows 95 and 98,
Fred Drakea88ef001999-06-18 19:11:25 +00001128where it is always \code{0}. Note that \POSIX{} does not specify the
1129meaning of the return value of the C \cfunction{system()} function,
1130so the return value of the Python function is system-dependent.
Fred Drakec37b65e2001-11-28 07:26:15 +00001131Availability: \UNIX, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +00001132\end{funcdesc}
1133
1134\begin{funcdesc}{times}{}
Fred Drake8ee679f2001-07-14 02:50:55 +00001135Return a 5-tuple of floating point numbers indicating accumulated
1136(processor or other)
Fred Drake215fe2f1999-02-02 19:02:35 +00001137times, in seconds. The items are: user time, system time, children's
1138user time, children's system time, and elapsed real time since a fixed
Fred Drakeec6baaf1999-04-21 18:13:31 +00001139point in the past, in that order. See the \UNIX{} manual page
1140\manpage{times}{2} or the corresponding Windows Platform API
1141documentation.
Fred Drakec37b65e2001-11-28 07:26:15 +00001142Availability: \UNIX, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +00001143\end{funcdesc}
1144
1145\begin{funcdesc}{wait}{}
1146Wait for completion of a child process, and return a tuple containing
1147its pid and exit status indication: a 16-bit number, whose low byte is
1148the signal number that killed the process, and whose high byte is the
1149exit status (if the signal number is zero); the high bit of the low
1150byte is set if a core file was produced.
Fred Drakec37b65e2001-11-28 07:26:15 +00001151Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +00001152\end{funcdesc}
1153
1154\begin{funcdesc}{waitpid}{pid, options}
Fred Drake31e5e371999-08-13 13:36:33 +00001155Wait for completion of a child process given by process id \var{pid},
1156and return a tuple containing its process id and exit status
1157indication (encoded as for \function{wait()}). The semantics of the
1158call are affected by the value of the integer \var{options}, which
1159should be \code{0} for normal operation.
Fred Drakec37b65e2001-11-28 07:26:15 +00001160Availability: \UNIX.
Fred Drake31e5e371999-08-13 13:36:33 +00001161
1162If \var{pid} is greater than \code{0}, \function{waitpid()} requests
1163status information for that specific process. If \var{pid} is
1164\code{0}, the request is for the status of any child in the process
1165group of the current process. If \var{pid} is \code{-1}, the request
1166pertains to any child of the current process. If \var{pid} is less
1167than \code{-1}, status is requested for any process in the process
1168group \code{-\var{pid}} (the absolute value of \var{pid}).
Fred Drake215fe2f1999-02-02 19:02:35 +00001169\end{funcdesc}
1170
1171\begin{datadesc}{WNOHANG}
1172The option for \function{waitpid()} to avoid hanging if no child
1173process status is available immediately.
Fred Drakec37b65e2001-11-28 07:26:15 +00001174Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +00001175\end{datadesc}
1176
Fred Drake38e5d272000-04-03 20:13:55 +00001177The following functions take a process status code as returned by
1178\function{system()}, \function{wait()}, or \function{waitpid()} as a
1179parameter. They may be used to determine the disposition of a
1180process.
Fred Drake215fe2f1999-02-02 19:02:35 +00001181
1182\begin{funcdesc}{WIFSTOPPED}{status}
1183Return true if the process has been stopped.
Fred Drakec37b65e2001-11-28 07:26:15 +00001184Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +00001185\end{funcdesc}
1186
1187\begin{funcdesc}{WIFSIGNALED}{status}
1188Return true if the process exited due to a signal.
Fred Drakec37b65e2001-11-28 07:26:15 +00001189Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +00001190\end{funcdesc}
1191
1192\begin{funcdesc}{WIFEXITED}{status}
1193Return true if the process exited using the \manpage{exit}{2} system
1194call.
Fred Drakec37b65e2001-11-28 07:26:15 +00001195Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +00001196\end{funcdesc}
1197
1198\begin{funcdesc}{WEXITSTATUS}{status}
1199If \code{WIFEXITED(\var{status})} is true, return the integer
1200parameter to the \manpage{exit}{2} system call. Otherwise, the return
1201value is meaningless.
Fred Drakec37b65e2001-11-28 07:26:15 +00001202Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +00001203\end{funcdesc}
1204
1205\begin{funcdesc}{WSTOPSIG}{status}
Fred Drake35c3ffd1999-03-04 14:08:10 +00001206Return the signal which caused the process to stop.
Fred Drakec37b65e2001-11-28 07:26:15 +00001207Availability: \UNIX.
Fred Drake35c3ffd1999-03-04 14:08:10 +00001208\end{funcdesc}
1209
1210\begin{funcdesc}{WTERMSIG}{status}
Fred Drake215fe2f1999-02-02 19:02:35 +00001211Return the signal which caused the process to exit.
Fred Drakec37b65e2001-11-28 07:26:15 +00001212Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +00001213\end{funcdesc}
1214
1215
Thomas Woutersf8316632000-07-16 19:01:10 +00001216\subsection{Miscellaneous System Information \label{os-path}}
Fred Drake88f6ca21999-12-15 19:39:04 +00001217
1218
1219\begin{funcdesc}{confstr}{name}
1220Return string-valued system configuration values.
1221\var{name} specifies the configuration value to retrieve; it may be a
1222string which is the name of a defined system value; these names are
Fred Drake8ee679f2001-07-14 02:50:55 +00001223specified in a number of standards (\POSIX, \UNIX 95, \UNIX 98, and
Fred Drake88f6ca21999-12-15 19:39:04 +00001224others). Some platforms define additional names as well. The names
1225known to the host operating system are given in the
1226\code{confstr_names} dictionary. For configuration variables not
1227included in that mapping, passing an integer for \var{name} is also
1228accepted.
Fred Drakec37b65e2001-11-28 07:26:15 +00001229Availability: \UNIX.
Fred Drake88f6ca21999-12-15 19:39:04 +00001230
1231If the configuration value specified by \var{name} isn't defined, the
1232empty string is returned.
1233
1234If \var{name} is a string and is not known, \exception{ValueError} is
1235raised. If a specific value for \var{name} is not supported by the
1236host system, even if it is included in \code{confstr_names}, an
1237\exception{OSError} is raised with \constant{errno.EINVAL} for the
1238error number.
1239\end{funcdesc}
1240
1241\begin{datadesc}{confstr_names}
1242Dictionary mapping names accepted by \function{confstr()} to the
1243integer values defined for those names by the host operating system.
1244This can be used to determine the set of names known to the system.
1245Availability: \UNIX.
1246\end{datadesc}
1247
1248\begin{funcdesc}{sysconf}{name}
1249Return integer-valued system configuration values.
1250If the configuration value specified by \var{name} isn't defined,
1251\code{-1} is returned. The comments regarding the \var{name}
1252parameter for \function{confstr()} apply here as well; the dictionary
1253that provides information on the known names is given by
1254\code{sysconf_names}.
Fred Drakec37b65e2001-11-28 07:26:15 +00001255Availability: \UNIX.
Fred Drake88f6ca21999-12-15 19:39:04 +00001256\end{funcdesc}
1257
1258\begin{datadesc}{sysconf_names}
1259Dictionary mapping names accepted by \function{sysconf()} to the
1260integer values defined for those names by the host operating system.
1261This can be used to determine the set of names known to the system.
1262Availability: \UNIX.
1263\end{datadesc}
1264
Fred Drake215fe2f1999-02-02 19:02:35 +00001265
1266The follow data values are used to support path manipulation
1267operations. These are defined for all platforms.
1268
1269Higher-level operations on pathnames are defined in the
1270\refmodule{os.path} module.
1271
1272
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00001273\begin{datadesc}{curdir}
Fred Drake8ee679f2001-07-14 02:50:55 +00001274The constant string used by the operating system to refer to the current
1275directory.
Fred Drake907e76b2001-07-06 20:30:11 +00001276For example: \code{'.'} for \POSIX{} or \code{':'} for the Macintosh.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00001277\end{datadesc}
1278
1279\begin{datadesc}{pardir}
Fred Drake8ee679f2001-07-14 02:50:55 +00001280The constant string used by the operating system to refer to the parent
1281directory.
Fred Drake907e76b2001-07-06 20:30:11 +00001282For example: \code{'..'} for \POSIX{} or \code{'::'} for the Macintosh.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00001283\end{datadesc}
1284
1285\begin{datadesc}{sep}
Fred Drake8ee679f2001-07-14 02:50:55 +00001286The character used by the operating system to separate pathname components,
Fred Drake907e76b2001-07-06 20:30:11 +00001287for example, \character{/} for \POSIX{} or \character{:} for the
1288Macintosh. Note that knowing this is not sufficient to be able to
1289parse or concatenate pathnames --- use \function{os.path.split()} and
Fred Drake1a3c2a01998-08-06 15:18:23 +00001290\function{os.path.join()} --- but it is occasionally useful.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00001291\end{datadesc}
1292
Guido van Rossumb2afc811997-08-29 22:37:44 +00001293\begin{datadesc}{altsep}
Fred Drake8ee679f2001-07-14 02:50:55 +00001294An alternative character used by the operating system to separate pathname
1295components, or \code{None} if only one separator character exists. This is
1296set to \character{/} on DOS and Windows systems where \code{sep} is a
1297backslash.
Guido van Rossumb2afc811997-08-29 22:37:44 +00001298\end{datadesc}
1299
Guido van Rossum470be141995-03-17 16:07:09 +00001300\begin{datadesc}{pathsep}
Fred Drake8ee679f2001-07-14 02:50:55 +00001301The character conventionally used by the operating system to separate
1302search patch components (as in \envvar{PATH}), such as \character{:} for
1303\POSIX{} or \character{;} for DOS and Windows.
Guido van Rossum9c59ce91998-06-30 15:54:27 +00001304\end{datadesc}
1305
Guido van Rossum470be141995-03-17 16:07:09 +00001306\begin{datadesc}{defpath}
Fred Drake6995bb62001-11-29 20:48:44 +00001307The default search path used by \function{exec*p*()} and
1308\function{spawn*p*()} if the environment doesn't have a \code{'PATH'}
1309key.
Guido van Rossum470be141995-03-17 16:07:09 +00001310\end{datadesc}
1311
Fred Drake215fe2f1999-02-02 19:02:35 +00001312\begin{datadesc}{linesep}
1313The string used to separate (or, rather, terminate) lines on the
Fred Drake907e76b2001-07-06 20:30:11 +00001314current platform. This may be a single character, such as \code{'\e
Fred Drake6995bb62001-11-29 20:48:44 +00001315n'} for \POSIX{} or \code{'\e r'} for Mac OS, or multiple characters,
Fred Drake8ee679f2001-07-14 02:50:55 +00001316for example, \code{'\e r\e n'} for DOS and Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +00001317\end{datadesc}