blob: 0586905a45a5c61d58bfe75d0608e4055e4bbbfb [file] [log] [blame]
Fred Drake295da241998-08-10 19:42:37 +00001\section{\module{os} ---
Fred Drake215fe2f1999-02-02 19:02:35 +00002 Miscellaneous OS interfaces}
Fred Drakeb91e9341998-07-23 17:59:49 +00003
Fred Drakeec6baaf1999-04-21 18:13:31 +00004\declaremodule{standard}{os}
Fred Drakeb91e9341998-07-23 17:59:49 +00005\modulesynopsis{Miscellaneous OS interfaces.}
6
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
9(OS) dependent functionality than importing an OS dependent built-in
Fred Drake2f979011999-06-11 18:28:37 +000010module like \refmodule{posix} or \module{nt}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000011
Fred Drake215fe2f1999-02-02 19:02:35 +000012This module searches for an OS 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 Drake215fe2f1999-02-02 19:02:35 +000014as found there. The design of all Python's built-in OS dependent
15modules is such that as long as the same functionality is available,
16it uses the same interface; e.g., 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
21Extensions peculiar to a particular OS are also available through the
Fred Drakec4f15af1998-03-10 03:17:26 +000022\module{os} module, but using them is of course a threat to
23portability!
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}
27instead of directly from the OS dependent built-in module, so there
28should 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}
45This exception is raised when a function returns a
46system-related error (e.g., not for illegal argument types). This is
47also known as the built-in exception \exception{OSError}. The
48accompanying 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
58involve a file system path (e.g. \function{chdir()} or
59\function{unlink()}), the exception instance will contain a third
60attribute, \member{filename}, which is the file name passed to the
61function.
62
63When exceptions are strings, the string for the exception is
64\code{'OSError'}.
65\end{excdesc}
Guido van Rossum470be141995-03-17 16:07:09 +000066
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000067\begin{datadesc}{name}
Guido van Rossum470be141995-03-17 16:07:09 +000068The name of the OS dependent module imported. The following names
69have currently been registered: \code{'posix'}, \code{'nt'},
Fred Drake933d5a71999-09-17 14:38:39 +000070\code{'dos'}, \code{'mac'}, \code{'os2'}, \code{'ce'}, \code{'java'}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000071\end{datadesc}
72
73\begin{datadesc}{path}
74The corresponding OS dependent standard module for pathname
Fred Drake215fe2f1999-02-02 19:02:35 +000075operations, e.g., \module{posixpath} or \module{macpath}. Thus, given
76the proper imports, \code{os.path.split(\var{file})} is equivalent to but
77more portable than \code{posixpath.split(\var{file})}. Note that this
78is also a valid module: it may be imported directly as
79\refmodule{os.path}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000080\end{datadesc}
81
Fred Drake215fe2f1999-02-02 19:02:35 +000082
83
84\subsection{Process Parameters \label{os-procinfo}}
85
86These functions and data items provide information and operate on the
87current process and user.
88
Fred Drake215fe2f1999-02-02 19:02:35 +000089\begin{datadesc}{environ}
Fred Drake0e1de8b1999-04-29 12:57:32 +000090A mapping object representing the string environment. For example,
91\code{environ['HOME']} is the pathname of your home directory (on some
92platforms), and is equivalent to \code{getenv("HOME")} in C.
Fred Drake215fe2f1999-02-02 19:02:35 +000093
94If the platform supports the \function{putenv()} function, this
95mapping may be used to modify the environment as well as query the
96environment. \function{putenv()} will be called automatically when
97the mapping is modified.
98
99If \function{putenv()} is not provided, this mapping may be passed to
100the appropriate process-creation functions to cause child processes to
101use a modified environment.
102\end{datadesc}
103
Fred Drake6db897c1999-07-12 16:49:30 +0000104\begin{funcdescni}{chdir}{path}
105\funclineni{getcwd}{}
106These functions are described in ``Files and Directories'' (section
107\ref{os-file-dir}).
108\end{funcdescni}
Fred Drake215fe2f1999-02-02 19:02:35 +0000109
Fred Drake18f7a451999-12-09 22:11:43 +0000110\begin{funcdesc}{ctermid}{}
111Return the filename corresponding to the controlling terminal of the
112process.
113Availability: \UNIX{}.
114\end{funcdesc}
115
Fred Drake215fe2f1999-02-02 19:02:35 +0000116\begin{funcdesc}{getegid}{}
117Return the current process' effective group id.
118Availability: \UNIX{}.
119\end{funcdesc}
120
121\begin{funcdesc}{geteuid}{}
Fred Drake6b330ba81999-05-25 13:42:26 +0000122\index{user!effective id}
Fred Drake215fe2f1999-02-02 19:02:35 +0000123Return the current process' effective user id.
124Availability: \UNIX{}.
125\end{funcdesc}
126
127\begin{funcdesc}{getgid}{}
Fred Drake6b330ba81999-05-25 13:42:26 +0000128\index{process!group}
Fred Drake215fe2f1999-02-02 19:02:35 +0000129Return the current process' group id.
130Availability: \UNIX{}.
131\end{funcdesc}
132
Fred Drake88f6ca21999-12-15 19:39:04 +0000133\begin{funcdesc}{getgroups}{}
134Return list of supplemental group ids associated with the current
135process.
136Availability: \UNIX{}.
137\end{funcdesc}
138
139\begin{funcdesc}{getlogin}{}
140Return the actual login name for the current process, even if there
141are multiple login names which map to the same user id.
142Availability: \UNIX{}.
143\end{funcdesc}
144
Fred Drake215fe2f1999-02-02 19:02:35 +0000145\begin{funcdesc}{getpgrp}{}
146\index{process!group}
147Return the current process group id.
148Availability: \UNIX{}.
149\end{funcdesc}
150
151\begin{funcdesc}{getpid}{}
152\index{process!id}
153Return the current process id.
154Availability: \UNIX{}, Windows.
155\end{funcdesc}
156
157\begin{funcdesc}{getppid}{}
158\index{process!id of parent}
159Return the parent's process id.
160Availability: \UNIX{}.
161\end{funcdesc}
162
163\begin{funcdesc}{getuid}{}
Fred Drake6b330ba81999-05-25 13:42:26 +0000164\index{user!id}
Fred Drake215fe2f1999-02-02 19:02:35 +0000165Return the current process' user id.
166Availability: \UNIX{}.
167\end{funcdesc}
168
169\begin{funcdesc}{putenv}{varname, value}
170\index{environment variables!setting}
171Set the environment variable named \var{varname} to the string
172\var{value}. Such changes to the environment affect subprocesses
173started with \function{os.system()}, \function{popen()} or
174\function{fork()} and \function{execv()}.
175Availability: most flavors of \UNIX{}, Windows.
176
177When \function{putenv()} is
178supported, assignments to items in \code{os.environ} are automatically
179translated into corresponding calls to \function{putenv()}; however,
180calls to \function{putenv()} don't update \code{os.environ}, so it is
181actually preferable to assign to items of \code{os.environ}.
182\end{funcdesc}
183
Andrew M. Kuchling8d2f2b22000-07-13 01:26:58 +0000184\begin{funcdesc}{setegid}{egid}
185Set the current process's effective group id.
186Availability: \UNIX{}.
187\end{funcdesc}
188
189\begin{funcdesc}{seteuid}{euid}
190Set the current process's effective user id.
191Availability: \UNIX{}.
192\end{funcdesc}
193
Fred Drake215fe2f1999-02-02 19:02:35 +0000194\begin{funcdesc}{setgid}{gid}
195Set the current process' group id.
196Availability: \UNIX{}.
197\end{funcdesc}
198
199\begin{funcdesc}{setpgrp}{}
200Calls the system call \cfunction{setpgrp()} or \cfunction{setpgrp(0,
2010)} depending on which version is implemented (if any). See the
202\UNIX{} manual for the semantics.
203Availability: \UNIX{}.
204\end{funcdesc}
205
206\begin{funcdesc}{setpgid}{pid, pgrp}
207Calls the system call \cfunction{setpgid()}. See the \UNIX{} manual
208for the semantics.
209Availability: \UNIX{}.
210\end{funcdesc}
211
Andrew M. Kuchling8d2f2b22000-07-13 01:26:58 +0000212\begin{funcdesc}{setreuid}{ruid, euid}
213Set the current process's real and effective user ids.
214Availability: \UNIX{}.
215\end{funcdesc}
216
217\begin{funcdesc}{setregid}{rgid, egid}
218Set the current process's real and effective group ids.
219Availability: \UNIX{}.
220\end{funcdesc}
221
Fred Drake215fe2f1999-02-02 19:02:35 +0000222\begin{funcdesc}{setsid}{}
223Calls the system call \cfunction{setsid()}. See the \UNIX{} manual
224for the semantics.
225Availability: \UNIX{}.
226\end{funcdesc}
227
228\begin{funcdesc}{setuid}{uid}
Fred Drake6b330ba81999-05-25 13:42:26 +0000229\index{user!id, setting}
Fred Drake215fe2f1999-02-02 19:02:35 +0000230Set the current process' user id.
231Availability: \UNIX{}.
232\end{funcdesc}
233
234% placed in this section since it relates to errno.... a little weak ;-(
235\begin{funcdesc}{strerror}{code}
236Return the error message corresponding to the error code in
237\var{code}.
238Availability: \UNIX{}, Windows.
239\end{funcdesc}
240
241\begin{funcdesc}{umask}{mask}
242Set the current numeric umask and returns the previous umask.
243Availability: \UNIX{}, Windows.
244\end{funcdesc}
245
246\begin{funcdesc}{uname}{}
247Return a 5-tuple containing information identifying the current
248operating system. The tuple contains 5 strings:
249\code{(\var{sysname}, \var{nodename}, \var{release}, \var{version},
250\var{machine})}. Some systems truncate the nodename to 8
251characters or to the leading component; a better way to get the
252hostname is \function{socket.gethostname()}
253\withsubitem{(in module socket)}{\ttindex{gethostname()}}
254or even
255\withsubitem{(in module socket)}{\ttindex{gethostbyaddr()}}
256\code{socket.gethostbyaddr(socket.gethostname())}.
257Availability: recent flavors of \UNIX{}.
258\end{funcdesc}
259
260
261
262\subsection{File Object Creation \label{os-newstreams}}
263
264These functions create new file objects.
265
266
267\begin{funcdesc}{fdopen}{fd\optional{, mode\optional{, bufsize}}}
268Return an open file object connected to the file descriptor \var{fd}.
Fred Drake8c9fc001999-08-05 13:41:31 +0000269\index{I/O control!buffering}
Fred Drake215fe2f1999-02-02 19:02:35 +0000270The \var{mode} and \var{bufsize} arguments have the same meaning as
271the corresponding arguments to the built-in \function{open()}
272function.
273Availability: Macintosh, \UNIX{}, Windows.
274\end{funcdesc}
275
276\begin{funcdesc}{popen}{command\optional{, mode\optional{, bufsize}}}
277Open a pipe to or from \var{command}. The return value is an open
278file object connected to the pipe, which can be read or written
279depending on whether \var{mode} is \code{'r'} (default) or \code{'w'}.
280The \var{bufsize} argument has the same meaning as the corresponding
281argument to the built-in \function{open()} function. The exit status of
282the command (encoded in the format specified for \function{wait()}) is
283available as the return value of the \method{close()} method of the file
284object, except that when the exit status is zero (termination without
Fred Drake1319e3e2000-10-03 17:14:27 +0000285errors), \code{None} is returned.
Fred Drake215fe2f1999-02-02 19:02:35 +0000286Availability: \UNIX{}, Windows.
287\end{funcdesc}
288
Fred Drake18f7a451999-12-09 22:11:43 +0000289\begin{funcdesc}{tmpfile}{}
290Return a new file object opened in update mode (\samp{w+}). The file
291has no directory entries associated with it and will be automatically
292deleted once there are no file descriptors for the file.
293Availability: \UNIX{}.
294\end{funcdesc}
Fred Drake215fe2f1999-02-02 19:02:35 +0000295
296
Fred Drake8a9db992000-09-28 20:27:51 +0000297For each of these \function{popen()} variants, if \var{bufsize} is
298specified, it specifies the buffer size for the I/O pipes.
299\var{mode}, if provided, should be the string \code{'b'} or
300\code{'t'}; on Windows this is needed to determine whether the file
301objects should be opened in binary or text mode. The default value
302for \var{mode} is \code{'t'}.
303
304\begin{funcdesc}{popen2}{cmd\optional{, bufsize\optional{, mode}}}
305Executes \var{cmd} as a sub-process. Returns the file objects
306\code{(\var{child_stdin}, \var{child_stdout})}.
307\versionadded{2.0}
308\end{funcdesc}
309
310\begin{funcdesc}{popen3}{cmd\optional{, bufsize\optional{, mode}}}
311Executes \var{cmd} as a sub-process. Returns the file objects
312\code{(\var{child_stdin}, \var{child_stdout}, \var{child_stderr})}.
313\versionadded{2.0}
314\end{funcdesc}
315
316\begin{funcdesc}{popen4}{cmd\optional{, bufsize\optional{, mode}}}
317Executes \var{cmd} as a sub-process. Returns the file objects
318\code{(\var{child_stdin}, \var{child_stdout_and_stderr})}.
319\versionadded{2.0}
320\end{funcdesc}
321
322This functionality is also available in the \refmodule{popen2} module
323using functions of the same names, but the return values of those
324functions have a different order.
325
326
Fred Drake215fe2f1999-02-02 19:02:35 +0000327\subsection{File Descriptor Operations \label{os-fd-ops}}
328
329These functions operate on I/O streams referred to
330using file descriptors.
331
332
333\begin{funcdesc}{close}{fd}
334Close file descriptor \var{fd}.
335Availability: Macintosh, \UNIX{}, Windows.
336
337Note: this function is intended for low-level I/O and must be applied
338to a file descriptor as returned by \function{open()} or
339\function{pipe()}. To close a ``file object'' returned by the
340built-in function \function{open()} or by \function{popen()} or
341\function{fdopen()}, use its \method{close()} method.
342\end{funcdesc}
343
344\begin{funcdesc}{dup}{fd}
345Return a duplicate of file descriptor \var{fd}.
346Availability: Macintosh, \UNIX{}, Windows.
347\end{funcdesc}
348
349\begin{funcdesc}{dup2}{fd, fd2}
350Duplicate file descriptor \var{fd} to \var{fd2}, closing the latter
351first if necessary.
352Availability: \UNIX{}, Windows.
353\end{funcdesc}
354
Fred Drake88f6ca21999-12-15 19:39:04 +0000355\begin{funcdesc}{fpathconf}{fd, name}
Thomas Woutersf8316632000-07-16 19:01:10 +0000356Return system configuration information relevant to an open file.
Fred Drake88f6ca21999-12-15 19:39:04 +0000357\var{name} specifies the configuration value to retrieve; it may be a
358string which is the name of a defined system value; these names are
359specified in a number of standards (\POSIX.1, Unix95, Unix98, and
360others). Some platforms define additional names as well. The names
361known to the host operating system are given in the
362\code{pathconf_names} dictionary. For configuration variables not
363included in that mapping, passing an integer for \var{name} is also
364accepted.
365Availability: \UNIX{}.
366
367If \var{name} is a string and is not known, \exception{ValueError} is
368raised. If a specific value for \var{name} is not supported by the
369host system, even if it is included in \code{pathconf_names}, an
370\exception{OSError} is raised with \constant{errno.EINVAL} for the
371error number.
372\end{funcdesc}
373
Fred Drake215fe2f1999-02-02 19:02:35 +0000374\begin{funcdesc}{fstat}{fd}
375Return status for file descriptor \var{fd}, like \function{stat()}.
376Availability: \UNIX{}, Windows.
377\end{funcdesc}
378
379\begin{funcdesc}{fstatvfs}{fd}
380Return information about the filesystem containing the file associated
381with file descriptor \var{fd}, like \function{statvfs()}.
382Availability: \UNIX{}.
383\end{funcdesc}
384
385\begin{funcdesc}{ftruncate}{fd, length}
386Truncate the file corresponding to file descriptor \var{fd},
387so that it is at most \var{length} bytes in size.
388Availability: \UNIX{}.
389\end{funcdesc}
390
Skip Montanarod3725212000-07-19 17:30:58 +0000391\begin{funcdesc}{isatty}{fd}
392Return \code{1} if the file descriptor \var{fd} is open and connected to a
393tty(-like) device, else \code{0}.
394Availability: \UNIX{}
395\end{funcdesc}
396
Fred Drake215fe2f1999-02-02 19:02:35 +0000397\begin{funcdesc}{lseek}{fd, pos, how}
398Set the current position of file descriptor \var{fd} to position
399\var{pos}, modified by \var{how}: \code{0} to set the position
400relative to the beginning of the file; \code{1} to set it relative to
401the current position; \code{2} to set it relative to the end of the
402file.
403Availability: Macintosh, \UNIX{}, Windows.
404\end{funcdesc}
405
406\begin{funcdesc}{open}{file, flags\optional{, mode}}
407Open the file \var{file} and set various flags according to
408\var{flags} and possibly its mode according to \var{mode}.
409The default \var{mode} is \code{0777} (octal), and the current umask
410value is first masked out. Return the file descriptor for the newly
411opened file.
412Availability: Macintosh, \UNIX{}, Windows.
413
414For a description of the flag and mode values, see the C run-time
415documentation; flag constants (like \constant{O_RDONLY} and
416\constant{O_WRONLY}) are defined in this module too (see below).
417
418Note: this function is intended for low-level I/O. For normal usage,
419use the built-in function \function{open()}, which returns a ``file
420object'' with \method{read()} and \method{write()} methods (and many
421more).
422\end{funcdesc}
423
Fred Drakec82634c2000-06-28 17:27:48 +0000424\begin{funcdesc}{openpty}{}
425Open a new pseudo-terminal pair. Return a pair of file descriptors
426\code{(\var{master}, \var{slave})} for the pty and the tty,
427respectively. For a (slightly) more portable approach, use the
428\refmodule{pty}\refstmodindex{pty} module.
429Availability: Some flavors of \UNIX{}
430\end{funcdesc}
431
Fred Drake215fe2f1999-02-02 19:02:35 +0000432\begin{funcdesc}{pipe}{}
433Create a pipe. Return a pair of file descriptors \code{(\var{r},
434\var{w})} usable for reading and writing, respectively.
435Availability: \UNIX{}, Windows.
436\end{funcdesc}
437
438\begin{funcdesc}{read}{fd, n}
439Read at most \var{n} bytes from file descriptor \var{fd}.
440Return a string containing the bytes read.
441Availability: Macintosh, \UNIX{}, Windows.
442
443Note: this function is intended for low-level I/O and must be applied
444to a file descriptor as returned by \function{open()} or
445\function{pipe()}. To read a ``file object'' returned by the
446built-in function \function{open()} or by \function{popen()} or
447\function{fdopen()}, or \code{sys.stdin}, use its
448\method{read()} or \method{readline()} methods.
449\end{funcdesc}
450
451\begin{funcdesc}{tcgetpgrp}{fd}
452Return the process group associated with the terminal given by
453\var{fd} (an open file descriptor as returned by \function{open()}).
454Availability: \UNIX{}.
455\end{funcdesc}
456
457\begin{funcdesc}{tcsetpgrp}{fd, pg}
458Set the process group associated with the terminal given by
459\var{fd} (an open file descriptor as returned by \function{open()})
460to \var{pg}.
461Availability: \UNIX{}.
462\end{funcdesc}
463
464\begin{funcdesc}{ttyname}{fd}
465Return a string which specifies the terminal device associated with
466file-descriptor \var{fd}. If \var{fd} is not associated with a terminal
467device, an exception is raised.
468Availability: \UNIX{}.
469\end{funcdesc}
470
471\begin{funcdesc}{write}{fd, str}
472Write the string \var{str} to file descriptor \var{fd}.
473Return the number of bytes actually written.
474Availability: Macintosh, \UNIX{}, Windows.
475
476Note: this function is intended for low-level I/O and must be applied
477to a file descriptor as returned by \function{open()} or
478\function{pipe()}. To write a ``file object'' returned by the
479built-in function \function{open()} or by \function{popen()} or
480\function{fdopen()}, or \code{sys.stdout} or \code{sys.stderr}, use
481its \method{write()} method.
482\end{funcdesc}
483
484
485The following data items are available for use in constructing the
486\var{flags} parameter to the \function{open()} function.
487
488\begin{datadesc}{O_RDONLY}
489\dataline{O_WRONLY}
490\dataline{O_RDWR}
491\dataline{O_NDELAY}
492\dataline{O_NONBLOCK}
493\dataline{O_APPEND}
494\dataline{O_DSYNC}
495\dataline{O_RSYNC}
496\dataline{O_SYNC}
497\dataline{O_NOCTTY}
498\dataline{O_CREAT}
499\dataline{O_EXCL}
500\dataline{O_TRUNC}
501Options for the \var{flag} argument to the \function{open()} function.
502These can be bit-wise OR'd together.
503Availability: Macintosh, \UNIX{}, Windows.
504\end{datadesc}
505
Fred Drake3ac977e2000-08-11 20:19:51 +0000506\begin{datadesc}{O_BINARY}
507Option for the \var{flag} argument to the \function{open()} function.
508This can be bit-wise OR'd together with those listed above.
509Availability: Macintosh, Windows.
510% XXX need to check on the availability of this one.
511\end{datadesc}
512
Fred Drake215fe2f1999-02-02 19:02:35 +0000513
514\subsection{Files and Directories \label{os-file-dir}}
515
516\begin{funcdesc}{access}{path, mode}
Fred Drake38e5d272000-04-03 20:13:55 +0000517Check read/write/execute permissions for this process or existence of
518file \var{path}. \var{mode} should be \constant{F_OK} to test the
519existence of \var{path}, or it can be the inclusive OR of one or more
520of \constant{R_OK}, \constant{W_OK}, and \constant{X_OK} to test
521permissions. Return \code{1} if access is allowed, \code{0} if not.
522See the \UNIX{} man page \manpage{access}{2} for more information.
Fred Drake3ac977e2000-08-11 20:19:51 +0000523Availability: \UNIX{}, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000524\end{funcdesc}
525
Fred Drake38e5d272000-04-03 20:13:55 +0000526\begin{datadesc}{F_OK}
527 Value to pass as the \var{mode} parameter of \function{access()} to
528 test the existence of \var{path}.
529\end{datadesc}
530
531\begin{datadesc}{R_OK}
532 Value to include in the \var{mode} parameter of \function{access()}
533 to test the readability of \var{path}.
534\end{datadesc}
535
536\begin{datadesc}{W_OK}
537 Value to include in the \var{mode} parameter of \function{access()}
538 to test the writability of \var{path}.
539\end{datadesc}
540
541\begin{datadesc}{X_OK}
542 Value to include in the \var{mode} parameter of \function{access()}
543 to determine if \var{path} can be executed.
544\end{datadesc}
545
Fred Drake6db897c1999-07-12 16:49:30 +0000546\begin{funcdesc}{chdir}{path}
547\index{directory!changing}
548Change the current working directory to \var{path}.
549Availability: Macintosh, \UNIX{}, Windows.
550\end{funcdesc}
551
552\begin{funcdesc}{getcwd}{}
553Return a string representing the current working directory.
554Availability: Macintosh, \UNIX{}, Windows.
555\end{funcdesc}
556
Fred Drake215fe2f1999-02-02 19:02:35 +0000557\begin{funcdesc}{chmod}{path, mode}
558Change the mode of \var{path} to the numeric \var{mode}.
559Availability: \UNIX{}, Windows.
560\end{funcdesc}
561
562\begin{funcdesc}{chown}{path, uid, gid}
563Change the owner and group id of \var{path} to the numeric \var{uid}
564and \var{gid}.
565Availability: \UNIX{}.
566\end{funcdesc}
567
568\begin{funcdesc}{link}{src, dst}
569Create a hard link pointing to \var{src} named \var{dst}.
570Availability: \UNIX{}.
571\end{funcdesc}
572
573\begin{funcdesc}{listdir}{path}
574Return a list containing the names of the entries in the directory.
575The list is in arbitrary order. It does not include the special
576entries \code{'.'} and \code{'..'} even if they are present in the
577directory.
578Availability: Macintosh, \UNIX{}, Windows.
579\end{funcdesc}
580
581\begin{funcdesc}{lstat}{path}
582Like \function{stat()}, but do not follow symbolic links.
583Availability: \UNIX{}.
584\end{funcdesc}
585
586\begin{funcdesc}{mkfifo}{path\optional{, mode}}
587Create a FIFO (a named pipe) named \var{path} with numeric mode
588\var{mode}. The default \var{mode} is \code{0666} (octal). The current
589umask value is first masked out from the mode.
590Availability: \UNIX{}.
591
592FIFOs are pipes that can be accessed like regular files. FIFOs exist
593until they are deleted (for example with \function{os.unlink()}).
594Generally, FIFOs are used as rendezvous between ``client'' and
595``server'' type processes: the server opens the FIFO for reading, and
596the client opens it for writing. Note that \function{mkfifo()}
597doesn't open the FIFO --- it just creates the rendezvous point.
598\end{funcdesc}
599
600\begin{funcdesc}{mkdir}{path\optional{, mode}}
601Create a directory named \var{path} with numeric mode \var{mode}.
602The default \var{mode} is \code{0777} (octal). On some systems,
603\var{mode} is ignored. Where it is used, the current umask value is
604first masked out.
605Availability: Macintosh, \UNIX{}, Windows.
606\end{funcdesc}
607
608\begin{funcdesc}{makedirs}{path\optional{, mode}}
609\index{directory!creating}
610Recursive directory creation function. Like \function{mkdir()},
611but makes all intermediate-level directories needed to contain the
612leaf directory. Throws an \exception{error} exception if the leaf
613directory already exists or cannot be created. The default \var{mode}
614is \code{0777} (octal).
615\versionadded{1.5.2}
616\end{funcdesc}
617
Fred Drake88f6ca21999-12-15 19:39:04 +0000618\begin{funcdesc}{pathconf}{path, name}
Thomas Woutersf8316632000-07-16 19:01:10 +0000619Return system configuration information relevant to a named file.
Fred Drake88f6ca21999-12-15 19:39:04 +0000620\var{name} specifies the configuration value to retrieve; it may be a
621string which is the name of a defined system value; these names are
622specified in a number of standards (\POSIX.1, Unix95, Unix98, and
623others). Some platforms define additional names as well. The names
624known to the host operating system are given in the
625\code{pathconf_names} dictionary. For configuration variables not
626included in that mapping, passing an integer for \var{name} is also
627accepted.
628Availability: \UNIX{}.
629
630If \var{name} is a string and is not known, \exception{ValueError} is
631raised. If a specific value for \var{name} is not supported by the
632host system, even if it is included in \code{pathconf_names}, an
633\exception{OSError} is raised with \constant{errno.EINVAL} for the
634error number.
635\end{funcdesc}
636
637\begin{datadesc}{pathconf_names}
638Dictionary mapping names accepted by \function{pathconf()} and
639\function{fpathconf()} to the integer values defined for those names
640by the host operating system. This can be used to determine the set
641of names known to the system.
642Availability: \UNIX.
643\end{datadesc}
644
Fred Drake215fe2f1999-02-02 19:02:35 +0000645\begin{funcdesc}{readlink}{path}
646Return a string representing the path to which the symbolic link
647points.
648Availability: \UNIX{}.
649\end{funcdesc}
650
651\begin{funcdesc}{remove}{path}
652Remove the file \var{path}. See \function{rmdir()} below to remove a
653directory. This is identical to the \function{unlink()} function
654documented below.
655Availability: Macintosh, \UNIX{}, Windows.
656\end{funcdesc}
657
658\begin{funcdesc}{removedirs}{path}
659\index{directory!deleting}
660Recursive directory removal function. Works like
661\function{rmdir()} except that, if the leaf directory is
662successfully removed, directories corresponding to rightmost path
663segments will be pruned way until either the whole path is consumed or
664an error is raised (which is ignored, because it generally means that
665a parent directory is not empty). Throws an \exception{error}
666exception if the leaf directory could not be successfully removed.
667\versionadded{1.5.2}
668\end{funcdesc}
669
670\begin{funcdesc}{rename}{src, dst}
671Rename the file or directory \var{src} to \var{dst}.
672Availability: Macintosh, \UNIX{}, Windows.
673\end{funcdesc}
674
675\begin{funcdesc}{renames}{old, new}
676Recursive directory or file renaming function.
677Works like \function{rename()}, except creation of any intermediate
678directories needed to make the new pathname good is attempted first.
679After the rename, directories corresponding to rightmost path segments
680of the old name will be pruned away using \function{removedirs()}.
681
682Note: this function can fail with the new directory structure made if
683you lack permissions needed to remove the leaf directory or file.
684\versionadded{1.5.2}
685\end{funcdesc}
686
687\begin{funcdesc}{rmdir}{path}
688Remove the directory \var{path}.
689Availability: Macintosh, \UNIX{}, Windows.
690\end{funcdesc}
691
692\begin{funcdesc}{stat}{path}
693Perform a \cfunction{stat()} system call on the given path. The
694return value is a tuple of at least 10 integers giving the most
695important (and portable) members of the \emph{stat} structure, in the
696order
697\code{st_mode},
698\code{st_ino},
699\code{st_dev},
700\code{st_nlink},
701\code{st_uid},
702\code{st_gid},
703\code{st_size},
704\code{st_atime},
705\code{st_mtime},
706\code{st_ctime}.
707More items may be added at the end by some implementations.
708(On MS Windows, some items are filled with dummy values.)
709Availability: Macintosh, \UNIX{}, Windows.
710
711Note: The standard module \refmodule{stat}\refstmodindex{stat} defines
712functions and constants that are useful for extracting information
713from a \ctype{stat} structure.
714\end{funcdesc}
715
716\begin{funcdesc}{statvfs}{path}
717Perform a \cfunction{statvfs()} system call on the given path. The
Guido van Rossum0c9608c1999-02-03 16:32:37 +0000718return value is a tuple of 10 integers giving the most common
Fred Drake215fe2f1999-02-02 19:02:35 +0000719members of the \ctype{statvfs} structure, in the order
720\code{f_bsize},
721\code{f_frsize},
722\code{f_blocks},
723\code{f_bfree},
724\code{f_bavail},
725\code{f_files},
726\code{f_ffree},
727\code{f_favail},
Fred Drake215fe2f1999-02-02 19:02:35 +0000728\code{f_flag},
729\code{f_namemax}.
730Availability: \UNIX{}.
731
732Note: The standard module \module{statvfs}\refstmodindex{statvfs}
733defines constants that are useful for extracting information
734from a \ctype{statvfs} structure.
735\end{funcdesc}
736
737\begin{funcdesc}{symlink}{src, dst}
738Create a symbolic link pointing to \var{src} named \var{dst}.
739Availability: \UNIX{}.
740\end{funcdesc}
741
Fred Drake18f7a451999-12-09 22:11:43 +0000742\begin{funcdesc}{tempnam}{\optional{dir\optional{, prefix}}}
743Return a unique path name that is reasonable for creating a temporary
744file. This will be an absolute path that names a potential directory
745entry in the directory \var{dir} or a common location for temporary
746files if \var{dir} is omitted or \code{None}. If given and not
747\code{None}, \var{prefix} is used to provide a short prefix to the
748filename. Applications are responsible for properly creating and
749managing files created using paths returned by \function{tempnam()};
750no automatic cleanup is provided.
751\end{funcdesc}
752
753\begin{funcdesc}{tmpnam}{}
754Return a unique path name that is reasonable for creating a temporary
755file. This will be an absolute path that names a potential directory
756entry in a common location for temporary files. Applications are
757responsible for properly creating and managing files created using
758paths returned by \function{tmpnam()}; no automatic cleanup is
759provided.
760\end{funcdesc}
761
762\begin{datadesc}{TMP_MAX}
763The maximum number of unique names that \function{tmpnam()} will
764generate before reusing names.
765\end{datadesc}
766
Fred Drake215fe2f1999-02-02 19:02:35 +0000767\begin{funcdesc}{unlink}{path}
768Remove the file \var{path}. This is the same function as
769\function{remove()}; the \function{unlink()} name is its traditional
770\UNIX{} name.
771Availability: Macintosh, \UNIX{}, Windows.
772\end{funcdesc}
773
Barry Warsaw93a8eac2000-05-01 16:18:22 +0000774\begin{funcdesc}{utime}{path, times}
775Set the access and modified times of the file specified by \var{path}.
776If \var{times} is \code{None}, then the file's access and modified
777times are set to the current time. Otherwise, \var{times} must be a
Fred Drakee06d0252000-05-02 17:29:35 +00007782-tuple of numbers, of the form \code{(\var{atime}, \var{mtime})}
779which is used to set the access and modified times, respectively.
Fred Drake30f76ff2000-06-30 16:06:19 +0000780\versionchanged[added support for \code{None} for \var{times}]{2.0}
Fred Drake215fe2f1999-02-02 19:02:35 +0000781Availability: Macintosh, \UNIX{}, Windows.
782\end{funcdesc}
783
784
785\subsection{Process Management \label{os-process}}
786
Fred Drake18f7a451999-12-09 22:11:43 +0000787These functions may be used to create and manage processes.
Fred Drake215fe2f1999-02-02 19:02:35 +0000788
Fred Drake7be31152000-09-23 05:22:07 +0000789The various \function{exec*()} functions take a list of arguments for
790the new program loaded into the process. In each case, the first of
791these arguments is passed to the new program as its own name rather
792than as an argument a user may have typed on a command line. For the
793C programmer, this is the \code{argv[0]} passed to a program's
794\cfunction{main()}. For example, \samp{os.execv('/bin/echo', ['foo',
795'bar'])} will only print \samp{bar} on standard output; \samp{foo}
796will seem to be ignored.
797
Fred Drake215fe2f1999-02-02 19:02:35 +0000798
Fred Drake18f7a451999-12-09 22:11:43 +0000799\begin{funcdesc}{abort}{}
800Generate a \constant{SIGABRT} signal to the current process. On
801\UNIX, the default behavior is to produce a core dump; on Windows, the
802process immediately returns an exit code of \code{3}. Be aware that
803programs which use \function{signal.signal()} to register a handler
804for \constant{SIGABRT} will behave differently.
805Availability: \UNIX, Windows.
806\end{funcdesc}
807
Fred Drake215fe2f1999-02-02 19:02:35 +0000808\begin{funcdesc}{execl}{path, arg0, arg1, ...}
809This is equivalent to
810\samp{execv(\var{path}, (\var{arg0}, \var{arg1}, ...))}.
811Availability: \UNIX{}, Windows.
812\end{funcdesc}
813
814\begin{funcdesc}{execle}{path, arg0, arg1, ..., env}
815This is equivalent to
816\samp{execve(\var{path}, (\var{arg0}, \var{arg1}, ...), \var{env})}.
817Availability: \UNIX{}, Windows.
818\end{funcdesc}
819
820\begin{funcdesc}{execlp}{path, arg0, arg1, ...}
821This is equivalent to
822\samp{execvp(\var{path}, (\var{arg0}, \var{arg1}, ...))}.
823Availability: \UNIX{}, Windows.
824\end{funcdesc}
825
826\begin{funcdesc}{execv}{path, args}
827Execute the executable \var{path} with argument list \var{args},
828replacing the current process (i.e., the Python interpreter).
829The argument list may be a tuple or list of strings.
830Availability: \UNIX{}, Windows.
831\end{funcdesc}
832
833\begin{funcdesc}{execve}{path, args, env}
834Execute the executable \var{path} with argument list \var{args},
835and environment \var{env},
836replacing the current process (i.e., the Python interpreter).
837The argument list may be a tuple or list of strings.
838The environment must be a dictionary mapping strings to strings.
839Availability: \UNIX{}, Windows.
840\end{funcdesc}
841
842\begin{funcdesc}{execvp}{path, args}
843This is like \samp{execv(\var{path}, \var{args})} but duplicates
844the shell's actions in searching for an executable file in a list of
845directories. The directory list is obtained from
846\code{environ['PATH']}.
847Availability: \UNIX{}, Windows.
848\end{funcdesc}
849
850\begin{funcdesc}{execvpe}{path, args, env}
851This is a cross between \function{execve()} and \function{execvp()}.
852The directory list is obtained from \code{\var{env}['PATH']}.
853Availability: \UNIX{}, Windows.
854\end{funcdesc}
855
856\begin{funcdesc}{_exit}{n}
857Exit to the system with status \var{n}, without calling cleanup
858handlers, flushing stdio buffers, etc.
859Availability: \UNIX{}, Windows.
860
861Note: the standard way to exit is \code{sys.exit(\var{n})}.
862\function{_exit()} should normally only be used in the child process
863after a \function{fork()}.
864\end{funcdesc}
865
866\begin{funcdesc}{fork}{}
867Fork a child process. Return \code{0} in the child, the child's
868process id in the parent.
869Availability: \UNIX{}.
870\end{funcdesc}
871
Fred Drakec82634c2000-06-28 17:27:48 +0000872\begin{funcdesc}{forkpty}{}
873Fork a child process, using a new pseudo-terminal as the child's
874controlling terminal. Return a pair of \code{(\var{pid}, \var{fd})},
875where \var{pid} is \code{0} in the child, the new child's process id
876in the parent, and \code{fd} is the file descriptor of the master end
877of the pseudo-terminal. For a more portable approach, use the
878\refmodule{pty} module.
879Availability: Some flavors of \UNIX{}
880\end{funcdesc}
881
Fred Drake215fe2f1999-02-02 19:02:35 +0000882\begin{funcdesc}{kill}{pid, sig}
883\index{process!killing}
884\index{process!signalling}
885Kill the process \var{pid} with signal \var{sig}.
886Availability: \UNIX{}.
887\end{funcdesc}
888
889\begin{funcdesc}{nice}{increment}
890Add \var{increment} to the process's ``niceness''. Return the new
891niceness.
892Availability: \UNIX{}.
893\end{funcdesc}
894
895\begin{funcdesc}{plock}{op}
896Lock program segments into memory. The value of \var{op}
897(defined in \code{<sys/lock.h>}) determines which segments are locked.
Fred Drake39063631999-02-26 14:05:02 +0000898Availability: \UNIX{}.
Fred Drake215fe2f1999-02-02 19:02:35 +0000899\end{funcdesc}
900
901\begin{funcdesc}{spawnv}{mode, path, args}
902Execute the program \var{path} in a new process, passing the arguments
903specified in \var{args} as command-line parameters. \var{args} may be
904a list or a tuple. \var{mode} is a magic operational constant. See
905the Visual \Cpp{} Runtime Library documentation for further
Fred Drake22702081999-07-02 14:01:03 +0000906information; the constants are exposed to the Python programmer as
907listed below.
Fred Drake15861b22000-02-29 05:19:38 +0000908Availability: \UNIX{}, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000909\versionadded{1.5.2}
910\end{funcdesc}
911
912\begin{funcdesc}{spawnve}{mode, path, args, env}
913Execute the program \var{path} in a new process, passing the arguments
914specified in \var{args} as command-line parameters and the contents of
915the mapping \var{env} as the environment. \var{args} may be a list or
916a tuple. \var{mode} is a magic operational constant. See the Visual
Fred Drake22702081999-07-02 14:01:03 +0000917\Cpp{} Runtime Library documentation for further information; the
918constants are exposed to the Python programmer as listed below.
Fred Drake15861b22000-02-29 05:19:38 +0000919Availability: \UNIX{}, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000920\versionadded{1.5.2}
921\end{funcdesc}
922
Fred Drake9329e5e1999-02-16 19:40:19 +0000923\begin{datadesc}{P_WAIT}
924\dataline{P_NOWAIT}
925\dataline{P_NOWAITO}
Fred Drake215fe2f1999-02-02 19:02:35 +0000926Possible values for the \var{mode} parameter to \function{spawnv()}
927and \function{spawnve()}.
Fred Drake15861b22000-02-29 05:19:38 +0000928Availability: \UNIX{}, Windows.
929\versionadded{1.5.2}
930\end{datadesc}
931
932\begin{datadesc}{P_OVERLAY}
933\dataline{P_DETACH}
934Possible values for the \var{mode} parameter to \function{spawnv()}
935and \function{spawnve()}. These are less portable than those listed
936above.
Fred Drake215fe2f1999-02-02 19:02:35 +0000937Availability: Windows.
938\versionadded{1.5.2}
939\end{datadesc}
940
Fred Drake4ce4f2e2000-09-29 04:15:19 +0000941\begin{funcdesc}{startfile}{path}
942Start a file with its associated application. This acts like
943double-clicking the file in Windows Explorer, or giving the file name
944as an argument to the DOS \program{start} command: the file is opened
945with whatever application (if any) its extension is associated.
946
947\function{startfile()} returns as soon as the associated application
948is launched. There is no option to wait for the application to close,
949and no way to retrieve the application's exit status. The \var{path}
950parameter is relative to the current directory. If you want to use an
951absolute path, make sure the first character is not a slash
952(\character{/}); the underlying Win32 \cfunction{ShellExecute()}
953function doesn't work it is. Use the \function{os.path.normpath()}
954function to ensure that the path is properly encoded for Win32.
955Availability: Windows.
956\versionadded{2.0}
957\end{funcdesc}
958
Fred Drake215fe2f1999-02-02 19:02:35 +0000959\begin{funcdesc}{system}{command}
960Execute the command (a string) in a subshell. This is implemented by
961calling the Standard C function \cfunction{system()}, and has the
Fred Drakeec6baaf1999-04-21 18:13:31 +0000962same limitations. Changes to \code{posix.environ}, \code{sys.stdin},
Fred Drake215fe2f1999-02-02 19:02:35 +0000963etc.\ are not reflected in the environment of the executed command.
964The return value is the exit status of the process encoded in the
Fred Drake7a621281999-06-10 15:07:05 +0000965format specified for \function{wait()}, except on Windows 95 and 98,
Fred Drakea88ef001999-06-18 19:11:25 +0000966where it is always \code{0}. Note that \POSIX{} does not specify the
967meaning of the return value of the C \cfunction{system()} function,
968so the return value of the Python function is system-dependent.
Fred Drake215fe2f1999-02-02 19:02:35 +0000969Availability: \UNIX{}, Windows.
970\end{funcdesc}
971
972\begin{funcdesc}{times}{}
973Return a 5-tuple of floating point numbers indicating accumulated (CPU
974or other)
975times, in seconds. The items are: user time, system time, children's
976user time, children's system time, and elapsed real time since a fixed
Fred Drakeec6baaf1999-04-21 18:13:31 +0000977point in the past, in that order. See the \UNIX{} manual page
978\manpage{times}{2} or the corresponding Windows Platform API
979documentation.
Fred Drake215fe2f1999-02-02 19:02:35 +0000980Availability: \UNIX{}, Windows.
981\end{funcdesc}
982
983\begin{funcdesc}{wait}{}
984Wait for completion of a child process, and return a tuple containing
985its pid and exit status indication: a 16-bit number, whose low byte is
986the signal number that killed the process, and whose high byte is the
987exit status (if the signal number is zero); the high bit of the low
988byte is set if a core file was produced.
989Availability: \UNIX{}.
990\end{funcdesc}
991
992\begin{funcdesc}{waitpid}{pid, options}
Fred Drake31e5e371999-08-13 13:36:33 +0000993Wait for completion of a child process given by process id \var{pid},
994and return a tuple containing its process id and exit status
995indication (encoded as for \function{wait()}). The semantics of the
996call are affected by the value of the integer \var{options}, which
997should be \code{0} for normal operation.
Fred Drake215fe2f1999-02-02 19:02:35 +0000998Availability: \UNIX{}.
Fred Drake31e5e371999-08-13 13:36:33 +0000999
1000If \var{pid} is greater than \code{0}, \function{waitpid()} requests
1001status information for that specific process. If \var{pid} is
1002\code{0}, the request is for the status of any child in the process
1003group of the current process. If \var{pid} is \code{-1}, the request
1004pertains to any child of the current process. If \var{pid} is less
1005than \code{-1}, status is requested for any process in the process
1006group \code{-\var{pid}} (the absolute value of \var{pid}).
Fred Drake215fe2f1999-02-02 19:02:35 +00001007\end{funcdesc}
1008
1009\begin{datadesc}{WNOHANG}
1010The option for \function{waitpid()} to avoid hanging if no child
1011process status is available immediately.
1012Availability: \UNIX{}.
1013\end{datadesc}
1014
Fred Drake38e5d272000-04-03 20:13:55 +00001015The following functions take a process status code as returned by
1016\function{system()}, \function{wait()}, or \function{waitpid()} as a
1017parameter. They may be used to determine the disposition of a
1018process.
Fred Drake215fe2f1999-02-02 19:02:35 +00001019
1020\begin{funcdesc}{WIFSTOPPED}{status}
1021Return true if the process has been stopped.
1022Availability: \UNIX{}.
1023\end{funcdesc}
1024
1025\begin{funcdesc}{WIFSIGNALED}{status}
1026Return true if the process exited due to a signal.
1027Availability: \UNIX{}.
1028\end{funcdesc}
1029
1030\begin{funcdesc}{WIFEXITED}{status}
1031Return true if the process exited using the \manpage{exit}{2} system
1032call.
1033Availability: \UNIX{}.
1034\end{funcdesc}
1035
1036\begin{funcdesc}{WEXITSTATUS}{status}
1037If \code{WIFEXITED(\var{status})} is true, return the integer
1038parameter to the \manpage{exit}{2} system call. Otherwise, the return
1039value is meaningless.
1040Availability: \UNIX{}.
1041\end{funcdesc}
1042
1043\begin{funcdesc}{WSTOPSIG}{status}
Fred Drake35c3ffd1999-03-04 14:08:10 +00001044Return the signal which caused the process to stop.
1045Availability: \UNIX{}.
1046\end{funcdesc}
1047
1048\begin{funcdesc}{WTERMSIG}{status}
Fred Drake215fe2f1999-02-02 19:02:35 +00001049Return the signal which caused the process to exit.
1050Availability: \UNIX{}.
1051\end{funcdesc}
1052
1053
Thomas Woutersf8316632000-07-16 19:01:10 +00001054\subsection{Miscellaneous System Information \label{os-path}}
Fred Drake88f6ca21999-12-15 19:39:04 +00001055
1056
1057\begin{funcdesc}{confstr}{name}
1058Return string-valued system configuration values.
1059\var{name} specifies the configuration value to retrieve; it may be a
1060string which is the name of a defined system value; these names are
1061specified in a number of standards (\POSIX, Unix95, Unix98, and
1062others). Some platforms define additional names as well. The names
1063known to the host operating system are given in the
1064\code{confstr_names} dictionary. For configuration variables not
1065included in that mapping, passing an integer for \var{name} is also
1066accepted.
1067Availability: \UNIX{}.
1068
1069If the configuration value specified by \var{name} isn't defined, the
1070empty string is returned.
1071
1072If \var{name} is a string and is not known, \exception{ValueError} is
1073raised. If a specific value for \var{name} is not supported by the
1074host system, even if it is included in \code{confstr_names}, an
1075\exception{OSError} is raised with \constant{errno.EINVAL} for the
1076error number.
1077\end{funcdesc}
1078
1079\begin{datadesc}{confstr_names}
1080Dictionary mapping names accepted by \function{confstr()} to the
1081integer values defined for those names by the host operating system.
1082This can be used to determine the set of names known to the system.
1083Availability: \UNIX.
1084\end{datadesc}
1085
1086\begin{funcdesc}{sysconf}{name}
1087Return integer-valued system configuration values.
1088If the configuration value specified by \var{name} isn't defined,
1089\code{-1} is returned. The comments regarding the \var{name}
1090parameter for \function{confstr()} apply here as well; the dictionary
1091that provides information on the known names is given by
1092\code{sysconf_names}.
1093Availability: \UNIX{}.
1094\end{funcdesc}
1095
1096\begin{datadesc}{sysconf_names}
1097Dictionary mapping names accepted by \function{sysconf()} to the
1098integer values defined for those names by the host operating system.
1099This can be used to determine the set of names known to the system.
1100Availability: \UNIX.
1101\end{datadesc}
1102
Fred Drake215fe2f1999-02-02 19:02:35 +00001103
1104The follow data values are used to support path manipulation
1105operations. These are defined for all platforms.
1106
1107Higher-level operations on pathnames are defined in the
1108\refmodule{os.path} module.
1109
1110
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00001111\begin{datadesc}{curdir}
1112The constant string used by the OS to refer to the current directory,
Fred Drake1a3c2a01998-08-06 15:18:23 +00001113e.g.\ \code{'.'} for \POSIX{} or \code{':'} for the Macintosh.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00001114\end{datadesc}
1115
1116\begin{datadesc}{pardir}
1117The constant string used by the OS to refer to the parent directory,
Fred Drake1a3c2a01998-08-06 15:18:23 +00001118e.g.\ \code{'..'} for \POSIX{} or \code{'::'} for the Macintosh.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00001119\end{datadesc}
1120
1121\begin{datadesc}{sep}
Guido van Rossumb2afc811997-08-29 22:37:44 +00001122The character used by the OS to separate pathname components,
Fred Drake1a3c2a01998-08-06 15:18:23 +00001123e.g.\ \character{/} for \POSIX{} or \character{:} for the Macintosh.
1124Note that knowing this is not sufficient to be able to parse or
1125concatenate pathnames --- use \function{os.path.split()} and
1126\function{os.path.join()} --- but it is occasionally useful.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00001127\end{datadesc}
1128
Guido van Rossumb2afc811997-08-29 22:37:44 +00001129\begin{datadesc}{altsep}
1130An alternative character used by the OS to separate pathname components,
1131or \code{None} if only one separator character exists. This is set to
Fred Drake215fe2f1999-02-02 19:02:35 +00001132\character{/} on DOS and Windows systems where \code{sep} is a backslash.
Guido van Rossumb2afc811997-08-29 22:37:44 +00001133\end{datadesc}
1134
Guido van Rossum470be141995-03-17 16:07:09 +00001135\begin{datadesc}{pathsep}
1136The character conventionally used by the OS to separate search patch
Fred Drake1a3c2a01998-08-06 15:18:23 +00001137components (as in \envvar{PATH}), e.g.\ \character{:} for \POSIX{} or
Fred Drake215fe2f1999-02-02 19:02:35 +00001138\character{;} for DOS and Windows.
Guido van Rossum9c59ce91998-06-30 15:54:27 +00001139\end{datadesc}
1140
Guido van Rossum470be141995-03-17 16:07:09 +00001141\begin{datadesc}{defpath}
Fred Drake1a3c2a01998-08-06 15:18:23 +00001142The default search path used by \function{exec*p*()} if the environment
Guido van Rossum470be141995-03-17 16:07:09 +00001143doesn't have a \code{'PATH'} key.
1144\end{datadesc}
1145
Fred Drake215fe2f1999-02-02 19:02:35 +00001146\begin{datadesc}{linesep}
1147The string used to separate (or, rather, terminate) lines on the
Fred Drakeec6baaf1999-04-21 18:13:31 +00001148current platform. This may be a single character,
1149e.g.\ \code{'\e n'} for \POSIX{} or \code{'\e r'} for MacOS, or multiple
1150characters, e.g.\ \code{'\e r\e n'} for MS-DOS and MS Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +00001151\end{datadesc}