blob: 40e9573c434ba972bfdde40fb6c748ed403237d8 [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 Drake38e5d272000-04-03 20:13:55 +0000285errors), \code{None} is returned. \strong{Note:} This function
286behaves unreliably under Windows due to the native implementation of
287\cfunction{popen()}.
Fred Drake215fe2f1999-02-02 19:02:35 +0000288Availability: \UNIX{}, Windows.
289\end{funcdesc}
290
Fred Drake18f7a451999-12-09 22:11:43 +0000291\begin{funcdesc}{tmpfile}{}
292Return a new file object opened in update mode (\samp{w+}). The file
293has no directory entries associated with it and will be automatically
294deleted once there are no file descriptors for the file.
295Availability: \UNIX{}.
296\end{funcdesc}
Fred Drake215fe2f1999-02-02 19:02:35 +0000297
298
Fred Drake8a9db992000-09-28 20:27:51 +0000299For each of these \function{popen()} variants, if \var{bufsize} is
300specified, it specifies the buffer size for the I/O pipes.
301\var{mode}, if provided, should be the string \code{'b'} or
302\code{'t'}; on Windows this is needed to determine whether the file
303objects should be opened in binary or text mode. The default value
304for \var{mode} is \code{'t'}.
305
306\begin{funcdesc}{popen2}{cmd\optional{, bufsize\optional{, mode}}}
307Executes \var{cmd} as a sub-process. Returns the file objects
308\code{(\var{child_stdin}, \var{child_stdout})}.
309\versionadded{2.0}
310\end{funcdesc}
311
312\begin{funcdesc}{popen3}{cmd\optional{, bufsize\optional{, mode}}}
313Executes \var{cmd} as a sub-process. Returns the file objects
314\code{(\var{child_stdin}, \var{child_stdout}, \var{child_stderr})}.
315\versionadded{2.0}
316\end{funcdesc}
317
318\begin{funcdesc}{popen4}{cmd\optional{, bufsize\optional{, mode}}}
319Executes \var{cmd} as a sub-process. Returns the file objects
320\code{(\var{child_stdin}, \var{child_stdout_and_stderr})}.
321\versionadded{2.0}
322\end{funcdesc}
323
324This functionality is also available in the \refmodule{popen2} module
325using functions of the same names, but the return values of those
326functions have a different order.
327
328
Fred Drake215fe2f1999-02-02 19:02:35 +0000329\subsection{File Descriptor Operations \label{os-fd-ops}}
330
331These functions operate on I/O streams referred to
332using file descriptors.
333
334
335\begin{funcdesc}{close}{fd}
336Close file descriptor \var{fd}.
337Availability: Macintosh, \UNIX{}, Windows.
338
339Note: this function is intended for low-level I/O and must be applied
340to a file descriptor as returned by \function{open()} or
341\function{pipe()}. To close a ``file object'' returned by the
342built-in function \function{open()} or by \function{popen()} or
343\function{fdopen()}, use its \method{close()} method.
344\end{funcdesc}
345
346\begin{funcdesc}{dup}{fd}
347Return a duplicate of file descriptor \var{fd}.
348Availability: Macintosh, \UNIX{}, Windows.
349\end{funcdesc}
350
351\begin{funcdesc}{dup2}{fd, fd2}
352Duplicate file descriptor \var{fd} to \var{fd2}, closing the latter
353first if necessary.
354Availability: \UNIX{}, Windows.
355\end{funcdesc}
356
Fred Drake88f6ca21999-12-15 19:39:04 +0000357\begin{funcdesc}{fpathconf}{fd, name}
Thomas Woutersf8316632000-07-16 19:01:10 +0000358Return system configuration information relevant to an open file.
Fred Drake88f6ca21999-12-15 19:39:04 +0000359\var{name} specifies the configuration value to retrieve; it may be a
360string which is the name of a defined system value; these names are
361specified in a number of standards (\POSIX.1, Unix95, Unix98, and
362others). Some platforms define additional names as well. The names
363known to the host operating system are given in the
364\code{pathconf_names} dictionary. For configuration variables not
365included in that mapping, passing an integer for \var{name} is also
366accepted.
367Availability: \UNIX{}.
368
369If \var{name} is a string and is not known, \exception{ValueError} is
370raised. If a specific value for \var{name} is not supported by the
371host system, even if it is included in \code{pathconf_names}, an
372\exception{OSError} is raised with \constant{errno.EINVAL} for the
373error number.
374\end{funcdesc}
375
Fred Drake215fe2f1999-02-02 19:02:35 +0000376\begin{funcdesc}{fstat}{fd}
377Return status for file descriptor \var{fd}, like \function{stat()}.
378Availability: \UNIX{}, Windows.
379\end{funcdesc}
380
381\begin{funcdesc}{fstatvfs}{fd}
382Return information about the filesystem containing the file associated
383with file descriptor \var{fd}, like \function{statvfs()}.
384Availability: \UNIX{}.
385\end{funcdesc}
386
387\begin{funcdesc}{ftruncate}{fd, length}
388Truncate the file corresponding to file descriptor \var{fd},
389so that it is at most \var{length} bytes in size.
390Availability: \UNIX{}.
391\end{funcdesc}
392
Skip Montanarod3725212000-07-19 17:30:58 +0000393\begin{funcdesc}{isatty}{fd}
394Return \code{1} if the file descriptor \var{fd} is open and connected to a
395tty(-like) device, else \code{0}.
396Availability: \UNIX{}
397\end{funcdesc}
398
Fred Drake215fe2f1999-02-02 19:02:35 +0000399\begin{funcdesc}{lseek}{fd, pos, how}
400Set the current position of file descriptor \var{fd} to position
401\var{pos}, modified by \var{how}: \code{0} to set the position
402relative to the beginning of the file; \code{1} to set it relative to
403the current position; \code{2} to set it relative to the end of the
404file.
405Availability: Macintosh, \UNIX{}, Windows.
406\end{funcdesc}
407
408\begin{funcdesc}{open}{file, flags\optional{, mode}}
409Open the file \var{file} and set various flags according to
410\var{flags} and possibly its mode according to \var{mode}.
411The default \var{mode} is \code{0777} (octal), and the current umask
412value is first masked out. Return the file descriptor for the newly
413opened file.
414Availability: Macintosh, \UNIX{}, Windows.
415
416For a description of the flag and mode values, see the C run-time
417documentation; flag constants (like \constant{O_RDONLY} and
418\constant{O_WRONLY}) are defined in this module too (see below).
419
420Note: this function is intended for low-level I/O. For normal usage,
421use the built-in function \function{open()}, which returns a ``file
422object'' with \method{read()} and \method{write()} methods (and many
423more).
424\end{funcdesc}
425
Fred Drakec82634c2000-06-28 17:27:48 +0000426\begin{funcdesc}{openpty}{}
427Open a new pseudo-terminal pair. Return a pair of file descriptors
428\code{(\var{master}, \var{slave})} for the pty and the tty,
429respectively. For a (slightly) more portable approach, use the
430\refmodule{pty}\refstmodindex{pty} module.
431Availability: Some flavors of \UNIX{}
432\end{funcdesc}
433
Fred Drake215fe2f1999-02-02 19:02:35 +0000434\begin{funcdesc}{pipe}{}
435Create a pipe. Return a pair of file descriptors \code{(\var{r},
436\var{w})} usable for reading and writing, respectively.
437Availability: \UNIX{}, Windows.
438\end{funcdesc}
439
440\begin{funcdesc}{read}{fd, n}
441Read at most \var{n} bytes from file descriptor \var{fd}.
442Return a string containing the bytes read.
443Availability: Macintosh, \UNIX{}, Windows.
444
445Note: this function is intended for low-level I/O and must be applied
446to a file descriptor as returned by \function{open()} or
447\function{pipe()}. To read a ``file object'' returned by the
448built-in function \function{open()} or by \function{popen()} or
449\function{fdopen()}, or \code{sys.stdin}, use its
450\method{read()} or \method{readline()} methods.
451\end{funcdesc}
452
453\begin{funcdesc}{tcgetpgrp}{fd}
454Return the process group associated with the terminal given by
455\var{fd} (an open file descriptor as returned by \function{open()}).
456Availability: \UNIX{}.
457\end{funcdesc}
458
459\begin{funcdesc}{tcsetpgrp}{fd, pg}
460Set the process group associated with the terminal given by
461\var{fd} (an open file descriptor as returned by \function{open()})
462to \var{pg}.
463Availability: \UNIX{}.
464\end{funcdesc}
465
466\begin{funcdesc}{ttyname}{fd}
467Return a string which specifies the terminal device associated with
468file-descriptor \var{fd}. If \var{fd} is not associated with a terminal
469device, an exception is raised.
470Availability: \UNIX{}.
471\end{funcdesc}
472
473\begin{funcdesc}{write}{fd, str}
474Write the string \var{str} to file descriptor \var{fd}.
475Return the number of bytes actually written.
476Availability: Macintosh, \UNIX{}, Windows.
477
478Note: this function is intended for low-level I/O and must be applied
479to a file descriptor as returned by \function{open()} or
480\function{pipe()}. To write a ``file object'' returned by the
481built-in function \function{open()} or by \function{popen()} or
482\function{fdopen()}, or \code{sys.stdout} or \code{sys.stderr}, use
483its \method{write()} method.
484\end{funcdesc}
485
486
487The following data items are available for use in constructing the
488\var{flags} parameter to the \function{open()} function.
489
490\begin{datadesc}{O_RDONLY}
491\dataline{O_WRONLY}
492\dataline{O_RDWR}
493\dataline{O_NDELAY}
494\dataline{O_NONBLOCK}
495\dataline{O_APPEND}
496\dataline{O_DSYNC}
497\dataline{O_RSYNC}
498\dataline{O_SYNC}
499\dataline{O_NOCTTY}
500\dataline{O_CREAT}
501\dataline{O_EXCL}
502\dataline{O_TRUNC}
503Options for the \var{flag} argument to the \function{open()} function.
504These can be bit-wise OR'd together.
505Availability: Macintosh, \UNIX{}, Windows.
506\end{datadesc}
507
Fred Drake3ac977e2000-08-11 20:19:51 +0000508\begin{datadesc}{O_BINARY}
509Option for the \var{flag} argument to the \function{open()} function.
510This can be bit-wise OR'd together with those listed above.
511Availability: Macintosh, Windows.
512% XXX need to check on the availability of this one.
513\end{datadesc}
514
Fred Drake215fe2f1999-02-02 19:02:35 +0000515
516\subsection{Files and Directories \label{os-file-dir}}
517
518\begin{funcdesc}{access}{path, mode}
Fred Drake38e5d272000-04-03 20:13:55 +0000519Check read/write/execute permissions for this process or existence of
520file \var{path}. \var{mode} should be \constant{F_OK} to test the
521existence of \var{path}, or it can be the inclusive OR of one or more
522of \constant{R_OK}, \constant{W_OK}, and \constant{X_OK} to test
523permissions. Return \code{1} if access is allowed, \code{0} if not.
524See the \UNIX{} man page \manpage{access}{2} for more information.
Fred Drake3ac977e2000-08-11 20:19:51 +0000525Availability: \UNIX{}, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000526\end{funcdesc}
527
Fred Drake38e5d272000-04-03 20:13:55 +0000528\begin{datadesc}{F_OK}
529 Value to pass as the \var{mode} parameter of \function{access()} to
530 test the existence of \var{path}.
531\end{datadesc}
532
533\begin{datadesc}{R_OK}
534 Value to include in the \var{mode} parameter of \function{access()}
535 to test the readability of \var{path}.
536\end{datadesc}
537
538\begin{datadesc}{W_OK}
539 Value to include in the \var{mode} parameter of \function{access()}
540 to test the writability of \var{path}.
541\end{datadesc}
542
543\begin{datadesc}{X_OK}
544 Value to include in the \var{mode} parameter of \function{access()}
545 to determine if \var{path} can be executed.
546\end{datadesc}
547
Fred Drake6db897c1999-07-12 16:49:30 +0000548\begin{funcdesc}{chdir}{path}
549\index{directory!changing}
550Change the current working directory to \var{path}.
551Availability: Macintosh, \UNIX{}, Windows.
552\end{funcdesc}
553
554\begin{funcdesc}{getcwd}{}
555Return a string representing the current working directory.
556Availability: Macintosh, \UNIX{}, Windows.
557\end{funcdesc}
558
Fred Drake215fe2f1999-02-02 19:02:35 +0000559\begin{funcdesc}{chmod}{path, mode}
560Change the mode of \var{path} to the numeric \var{mode}.
561Availability: \UNIX{}, Windows.
562\end{funcdesc}
563
564\begin{funcdesc}{chown}{path, uid, gid}
565Change the owner and group id of \var{path} to the numeric \var{uid}
566and \var{gid}.
567Availability: \UNIX{}.
568\end{funcdesc}
569
570\begin{funcdesc}{link}{src, dst}
571Create a hard link pointing to \var{src} named \var{dst}.
572Availability: \UNIX{}.
573\end{funcdesc}
574
575\begin{funcdesc}{listdir}{path}
576Return a list containing the names of the entries in the directory.
577The list is in arbitrary order. It does not include the special
578entries \code{'.'} and \code{'..'} even if they are present in the
579directory.
580Availability: Macintosh, \UNIX{}, Windows.
581\end{funcdesc}
582
583\begin{funcdesc}{lstat}{path}
584Like \function{stat()}, but do not follow symbolic links.
585Availability: \UNIX{}.
586\end{funcdesc}
587
588\begin{funcdesc}{mkfifo}{path\optional{, mode}}
589Create a FIFO (a named pipe) named \var{path} with numeric mode
590\var{mode}. The default \var{mode} is \code{0666} (octal). The current
591umask value is first masked out from the mode.
592Availability: \UNIX{}.
593
594FIFOs are pipes that can be accessed like regular files. FIFOs exist
595until they are deleted (for example with \function{os.unlink()}).
596Generally, FIFOs are used as rendezvous between ``client'' and
597``server'' type processes: the server opens the FIFO for reading, and
598the client opens it for writing. Note that \function{mkfifo()}
599doesn't open the FIFO --- it just creates the rendezvous point.
600\end{funcdesc}
601
602\begin{funcdesc}{mkdir}{path\optional{, mode}}
603Create a directory named \var{path} with numeric mode \var{mode}.
604The default \var{mode} is \code{0777} (octal). On some systems,
605\var{mode} is ignored. Where it is used, the current umask value is
606first masked out.
607Availability: Macintosh, \UNIX{}, Windows.
608\end{funcdesc}
609
610\begin{funcdesc}{makedirs}{path\optional{, mode}}
611\index{directory!creating}
612Recursive directory creation function. Like \function{mkdir()},
613but makes all intermediate-level directories needed to contain the
614leaf directory. Throws an \exception{error} exception if the leaf
615directory already exists or cannot be created. The default \var{mode}
616is \code{0777} (octal).
617\versionadded{1.5.2}
618\end{funcdesc}
619
Fred Drake88f6ca21999-12-15 19:39:04 +0000620\begin{funcdesc}{pathconf}{path, name}
Thomas Woutersf8316632000-07-16 19:01:10 +0000621Return system configuration information relevant to a named file.
Fred Drake88f6ca21999-12-15 19:39:04 +0000622\var{name} specifies the configuration value to retrieve; it may be a
623string which is the name of a defined system value; these names are
624specified in a number of standards (\POSIX.1, Unix95, Unix98, and
625others). Some platforms define additional names as well. The names
626known to the host operating system are given in the
627\code{pathconf_names} dictionary. For configuration variables not
628included in that mapping, passing an integer for \var{name} is also
629accepted.
630Availability: \UNIX{}.
631
632If \var{name} is a string and is not known, \exception{ValueError} is
633raised. If a specific value for \var{name} is not supported by the
634host system, even if it is included in \code{pathconf_names}, an
635\exception{OSError} is raised with \constant{errno.EINVAL} for the
636error number.
637\end{funcdesc}
638
639\begin{datadesc}{pathconf_names}
640Dictionary mapping names accepted by \function{pathconf()} and
641\function{fpathconf()} to the integer values defined for those names
642by the host operating system. This can be used to determine the set
643of names known to the system.
644Availability: \UNIX.
645\end{datadesc}
646
Fred Drake215fe2f1999-02-02 19:02:35 +0000647\begin{funcdesc}{readlink}{path}
648Return a string representing the path to which the symbolic link
649points.
650Availability: \UNIX{}.
651\end{funcdesc}
652
653\begin{funcdesc}{remove}{path}
654Remove the file \var{path}. See \function{rmdir()} below to remove a
655directory. This is identical to the \function{unlink()} function
656documented below.
657Availability: Macintosh, \UNIX{}, Windows.
658\end{funcdesc}
659
660\begin{funcdesc}{removedirs}{path}
661\index{directory!deleting}
662Recursive directory removal function. Works like
663\function{rmdir()} except that, if the leaf directory is
664successfully removed, directories corresponding to rightmost path
665segments will be pruned way until either the whole path is consumed or
666an error is raised (which is ignored, because it generally means that
667a parent directory is not empty). Throws an \exception{error}
668exception if the leaf directory could not be successfully removed.
669\versionadded{1.5.2}
670\end{funcdesc}
671
672\begin{funcdesc}{rename}{src, dst}
673Rename the file or directory \var{src} to \var{dst}.
674Availability: Macintosh, \UNIX{}, Windows.
675\end{funcdesc}
676
677\begin{funcdesc}{renames}{old, new}
678Recursive directory or file renaming function.
679Works like \function{rename()}, except creation of any intermediate
680directories needed to make the new pathname good is attempted first.
681After the rename, directories corresponding to rightmost path segments
682of the old name will be pruned away using \function{removedirs()}.
683
684Note: this function can fail with the new directory structure made if
685you lack permissions needed to remove the leaf directory or file.
686\versionadded{1.5.2}
687\end{funcdesc}
688
689\begin{funcdesc}{rmdir}{path}
690Remove the directory \var{path}.
691Availability: Macintosh, \UNIX{}, Windows.
692\end{funcdesc}
693
694\begin{funcdesc}{stat}{path}
695Perform a \cfunction{stat()} system call on the given path. The
696return value is a tuple of at least 10 integers giving the most
697important (and portable) members of the \emph{stat} structure, in the
698order
699\code{st_mode},
700\code{st_ino},
701\code{st_dev},
702\code{st_nlink},
703\code{st_uid},
704\code{st_gid},
705\code{st_size},
706\code{st_atime},
707\code{st_mtime},
708\code{st_ctime}.
709More items may be added at the end by some implementations.
710(On MS Windows, some items are filled with dummy values.)
711Availability: Macintosh, \UNIX{}, Windows.
712
713Note: The standard module \refmodule{stat}\refstmodindex{stat} defines
714functions and constants that are useful for extracting information
715from a \ctype{stat} structure.
716\end{funcdesc}
717
718\begin{funcdesc}{statvfs}{path}
719Perform a \cfunction{statvfs()} system call on the given path. The
Guido van Rossum0c9608c1999-02-03 16:32:37 +0000720return value is a tuple of 10 integers giving the most common
Fred Drake215fe2f1999-02-02 19:02:35 +0000721members of the \ctype{statvfs} structure, in the order
722\code{f_bsize},
723\code{f_frsize},
724\code{f_blocks},
725\code{f_bfree},
726\code{f_bavail},
727\code{f_files},
728\code{f_ffree},
729\code{f_favail},
Fred Drake215fe2f1999-02-02 19:02:35 +0000730\code{f_flag},
731\code{f_namemax}.
732Availability: \UNIX{}.
733
734Note: The standard module \module{statvfs}\refstmodindex{statvfs}
735defines constants that are useful for extracting information
736from a \ctype{statvfs} structure.
737\end{funcdesc}
738
739\begin{funcdesc}{symlink}{src, dst}
740Create a symbolic link pointing to \var{src} named \var{dst}.
741Availability: \UNIX{}.
742\end{funcdesc}
743
Fred Drake18f7a451999-12-09 22:11:43 +0000744\begin{funcdesc}{tempnam}{\optional{dir\optional{, prefix}}}
745Return a unique path name that is reasonable for creating a temporary
746file. This will be an absolute path that names a potential directory
747entry in the directory \var{dir} or a common location for temporary
748files if \var{dir} is omitted or \code{None}. If given and not
749\code{None}, \var{prefix} is used to provide a short prefix to the
750filename. Applications are responsible for properly creating and
751managing files created using paths returned by \function{tempnam()};
752no automatic cleanup is provided.
753\end{funcdesc}
754
755\begin{funcdesc}{tmpnam}{}
756Return a unique path name that is reasonable for creating a temporary
757file. This will be an absolute path that names a potential directory
758entry in a common location for temporary files. Applications are
759responsible for properly creating and managing files created using
760paths returned by \function{tmpnam()}; no automatic cleanup is
761provided.
762\end{funcdesc}
763
764\begin{datadesc}{TMP_MAX}
765The maximum number of unique names that \function{tmpnam()} will
766generate before reusing names.
767\end{datadesc}
768
Fred Drake215fe2f1999-02-02 19:02:35 +0000769\begin{funcdesc}{unlink}{path}
770Remove the file \var{path}. This is the same function as
771\function{remove()}; the \function{unlink()} name is its traditional
772\UNIX{} name.
773Availability: Macintosh, \UNIX{}, Windows.
774\end{funcdesc}
775
Barry Warsaw93a8eac2000-05-01 16:18:22 +0000776\begin{funcdesc}{utime}{path, times}
777Set the access and modified times of the file specified by \var{path}.
778If \var{times} is \code{None}, then the file's access and modified
779times are set to the current time. Otherwise, \var{times} must be a
Fred Drakee06d0252000-05-02 17:29:35 +00007802-tuple of numbers, of the form \code{(\var{atime}, \var{mtime})}
781which is used to set the access and modified times, respectively.
Fred Drake30f76ff2000-06-30 16:06:19 +0000782\versionchanged[added support for \code{None} for \var{times}]{2.0}
Fred Drake215fe2f1999-02-02 19:02:35 +0000783Availability: Macintosh, \UNIX{}, Windows.
784\end{funcdesc}
785
786
787\subsection{Process Management \label{os-process}}
788
Fred Drake18f7a451999-12-09 22:11:43 +0000789These functions may be used to create and manage processes.
Fred Drake215fe2f1999-02-02 19:02:35 +0000790
Fred Drake7be31152000-09-23 05:22:07 +0000791The various \function{exec*()} functions take a list of arguments for
792the new program loaded into the process. In each case, the first of
793these arguments is passed to the new program as its own name rather
794than as an argument a user may have typed on a command line. For the
795C programmer, this is the \code{argv[0]} passed to a program's
796\cfunction{main()}. For example, \samp{os.execv('/bin/echo', ['foo',
797'bar'])} will only print \samp{bar} on standard output; \samp{foo}
798will seem to be ignored.
799
Fred Drake215fe2f1999-02-02 19:02:35 +0000800
Fred Drake18f7a451999-12-09 22:11:43 +0000801\begin{funcdesc}{abort}{}
802Generate a \constant{SIGABRT} signal to the current process. On
803\UNIX, the default behavior is to produce a core dump; on Windows, the
804process immediately returns an exit code of \code{3}. Be aware that
805programs which use \function{signal.signal()} to register a handler
806for \constant{SIGABRT} will behave differently.
807Availability: \UNIX, Windows.
808\end{funcdesc}
809
Fred Drake215fe2f1999-02-02 19:02:35 +0000810\begin{funcdesc}{execl}{path, arg0, arg1, ...}
811This is equivalent to
812\samp{execv(\var{path}, (\var{arg0}, \var{arg1}, ...))}.
813Availability: \UNIX{}, Windows.
814\end{funcdesc}
815
816\begin{funcdesc}{execle}{path, arg0, arg1, ..., env}
817This is equivalent to
818\samp{execve(\var{path}, (\var{arg0}, \var{arg1}, ...), \var{env})}.
819Availability: \UNIX{}, Windows.
820\end{funcdesc}
821
822\begin{funcdesc}{execlp}{path, arg0, arg1, ...}
823This is equivalent to
824\samp{execvp(\var{path}, (\var{arg0}, \var{arg1}, ...))}.
825Availability: \UNIX{}, Windows.
826\end{funcdesc}
827
828\begin{funcdesc}{execv}{path, args}
829Execute the executable \var{path} with argument list \var{args},
830replacing the current process (i.e., the Python interpreter).
831The argument list may be a tuple or list of strings.
832Availability: \UNIX{}, Windows.
833\end{funcdesc}
834
835\begin{funcdesc}{execve}{path, args, env}
836Execute the executable \var{path} with argument list \var{args},
837and environment \var{env},
838replacing the current process (i.e., the Python interpreter).
839The argument list may be a tuple or list of strings.
840The environment must be a dictionary mapping strings to strings.
841Availability: \UNIX{}, Windows.
842\end{funcdesc}
843
844\begin{funcdesc}{execvp}{path, args}
845This is like \samp{execv(\var{path}, \var{args})} but duplicates
846the shell's actions in searching for an executable file in a list of
847directories. The directory list is obtained from
848\code{environ['PATH']}.
849Availability: \UNIX{}, Windows.
850\end{funcdesc}
851
852\begin{funcdesc}{execvpe}{path, args, env}
853This is a cross between \function{execve()} and \function{execvp()}.
854The directory list is obtained from \code{\var{env}['PATH']}.
855Availability: \UNIX{}, Windows.
856\end{funcdesc}
857
858\begin{funcdesc}{_exit}{n}
859Exit to the system with status \var{n}, without calling cleanup
860handlers, flushing stdio buffers, etc.
861Availability: \UNIX{}, Windows.
862
863Note: the standard way to exit is \code{sys.exit(\var{n})}.
864\function{_exit()} should normally only be used in the child process
865after a \function{fork()}.
866\end{funcdesc}
867
868\begin{funcdesc}{fork}{}
869Fork a child process. Return \code{0} in the child, the child's
870process id in the parent.
871Availability: \UNIX{}.
872\end{funcdesc}
873
Fred Drakec82634c2000-06-28 17:27:48 +0000874\begin{funcdesc}{forkpty}{}
875Fork a child process, using a new pseudo-terminal as the child's
876controlling terminal. Return a pair of \code{(\var{pid}, \var{fd})},
877where \var{pid} is \code{0} in the child, the new child's process id
878in the parent, and \code{fd} is the file descriptor of the master end
879of the pseudo-terminal. For a more portable approach, use the
880\refmodule{pty} module.
881Availability: Some flavors of \UNIX{}
882\end{funcdesc}
883
Fred Drake215fe2f1999-02-02 19:02:35 +0000884\begin{funcdesc}{kill}{pid, sig}
885\index{process!killing}
886\index{process!signalling}
887Kill the process \var{pid} with signal \var{sig}.
888Availability: \UNIX{}.
889\end{funcdesc}
890
891\begin{funcdesc}{nice}{increment}
892Add \var{increment} to the process's ``niceness''. Return the new
893niceness.
894Availability: \UNIX{}.
895\end{funcdesc}
896
897\begin{funcdesc}{plock}{op}
898Lock program segments into memory. The value of \var{op}
899(defined in \code{<sys/lock.h>}) determines which segments are locked.
Fred Drake39063631999-02-26 14:05:02 +0000900Availability: \UNIX{}.
Fred Drake215fe2f1999-02-02 19:02:35 +0000901\end{funcdesc}
902
903\begin{funcdesc}{spawnv}{mode, path, args}
904Execute the program \var{path} in a new process, passing the arguments
905specified in \var{args} as command-line parameters. \var{args} may be
906a list or a tuple. \var{mode} is a magic operational constant. See
907the Visual \Cpp{} Runtime Library documentation for further
Fred Drake22702081999-07-02 14:01:03 +0000908information; the constants are exposed to the Python programmer as
909listed below.
Fred Drake15861b22000-02-29 05:19:38 +0000910Availability: \UNIX{}, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000911\versionadded{1.5.2}
912\end{funcdesc}
913
914\begin{funcdesc}{spawnve}{mode, path, args, env}
915Execute the program \var{path} in a new process, passing the arguments
916specified in \var{args} as command-line parameters and the contents of
917the mapping \var{env} as the environment. \var{args} may be a list or
918a tuple. \var{mode} is a magic operational constant. See the Visual
Fred Drake22702081999-07-02 14:01:03 +0000919\Cpp{} Runtime Library documentation for further information; the
920constants are exposed to the Python programmer as listed below.
Fred Drake15861b22000-02-29 05:19:38 +0000921Availability: \UNIX{}, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000922\versionadded{1.5.2}
923\end{funcdesc}
924
Fred Drake9329e5e1999-02-16 19:40:19 +0000925\begin{datadesc}{P_WAIT}
926\dataline{P_NOWAIT}
927\dataline{P_NOWAITO}
Fred Drake215fe2f1999-02-02 19:02:35 +0000928Possible values for the \var{mode} parameter to \function{spawnv()}
929and \function{spawnve()}.
Fred Drake15861b22000-02-29 05:19:38 +0000930Availability: \UNIX{}, Windows.
931\versionadded{1.5.2}
932\end{datadesc}
933
934\begin{datadesc}{P_OVERLAY}
935\dataline{P_DETACH}
936Possible values for the \var{mode} parameter to \function{spawnv()}
937and \function{spawnve()}. These are less portable than those listed
938above.
Fred Drake215fe2f1999-02-02 19:02:35 +0000939Availability: Windows.
940\versionadded{1.5.2}
941\end{datadesc}
942
943\begin{funcdesc}{system}{command}
944Execute the command (a string) in a subshell. This is implemented by
945calling the Standard C function \cfunction{system()}, and has the
Fred Drakeec6baaf1999-04-21 18:13:31 +0000946same limitations. Changes to \code{posix.environ}, \code{sys.stdin},
Fred Drake215fe2f1999-02-02 19:02:35 +0000947etc.\ are not reflected in the environment of the executed command.
948The return value is the exit status of the process encoded in the
Fred Drake7a621281999-06-10 15:07:05 +0000949format specified for \function{wait()}, except on Windows 95 and 98,
Fred Drakea88ef001999-06-18 19:11:25 +0000950where it is always \code{0}. Note that \POSIX{} does not specify the
951meaning of the return value of the C \cfunction{system()} function,
952so the return value of the Python function is system-dependent.
Fred Drake215fe2f1999-02-02 19:02:35 +0000953Availability: \UNIX{}, Windows.
954\end{funcdesc}
955
956\begin{funcdesc}{times}{}
957Return a 5-tuple of floating point numbers indicating accumulated (CPU
958or other)
959times, in seconds. The items are: user time, system time, children's
960user time, children's system time, and elapsed real time since a fixed
Fred Drakeec6baaf1999-04-21 18:13:31 +0000961point in the past, in that order. See the \UNIX{} manual page
962\manpage{times}{2} or the corresponding Windows Platform API
963documentation.
Fred Drake215fe2f1999-02-02 19:02:35 +0000964Availability: \UNIX{}, Windows.
965\end{funcdesc}
966
967\begin{funcdesc}{wait}{}
968Wait for completion of a child process, and return a tuple containing
969its pid and exit status indication: a 16-bit number, whose low byte is
970the signal number that killed the process, and whose high byte is the
971exit status (if the signal number is zero); the high bit of the low
972byte is set if a core file was produced.
973Availability: \UNIX{}.
974\end{funcdesc}
975
976\begin{funcdesc}{waitpid}{pid, options}
Fred Drake31e5e371999-08-13 13:36:33 +0000977Wait for completion of a child process given by process id \var{pid},
978and return a tuple containing its process id and exit status
979indication (encoded as for \function{wait()}). The semantics of the
980call are affected by the value of the integer \var{options}, which
981should be \code{0} for normal operation.
Fred Drake215fe2f1999-02-02 19:02:35 +0000982Availability: \UNIX{}.
Fred Drake31e5e371999-08-13 13:36:33 +0000983
984If \var{pid} is greater than \code{0}, \function{waitpid()} requests
985status information for that specific process. If \var{pid} is
986\code{0}, the request is for the status of any child in the process
987group of the current process. If \var{pid} is \code{-1}, the request
988pertains to any child of the current process. If \var{pid} is less
989than \code{-1}, status is requested for any process in the process
990group \code{-\var{pid}} (the absolute value of \var{pid}).
Fred Drake215fe2f1999-02-02 19:02:35 +0000991\end{funcdesc}
992
993\begin{datadesc}{WNOHANG}
994The option for \function{waitpid()} to avoid hanging if no child
995process status is available immediately.
996Availability: \UNIX{}.
997\end{datadesc}
998
Fred Drake38e5d272000-04-03 20:13:55 +0000999The following functions take a process status code as returned by
1000\function{system()}, \function{wait()}, or \function{waitpid()} as a
1001parameter. They may be used to determine the disposition of a
1002process.
Fred Drake215fe2f1999-02-02 19:02:35 +00001003
1004\begin{funcdesc}{WIFSTOPPED}{status}
1005Return true if the process has been stopped.
1006Availability: \UNIX{}.
1007\end{funcdesc}
1008
1009\begin{funcdesc}{WIFSIGNALED}{status}
1010Return true if the process exited due to a signal.
1011Availability: \UNIX{}.
1012\end{funcdesc}
1013
1014\begin{funcdesc}{WIFEXITED}{status}
1015Return true if the process exited using the \manpage{exit}{2} system
1016call.
1017Availability: \UNIX{}.
1018\end{funcdesc}
1019
1020\begin{funcdesc}{WEXITSTATUS}{status}
1021If \code{WIFEXITED(\var{status})} is true, return the integer
1022parameter to the \manpage{exit}{2} system call. Otherwise, the return
1023value is meaningless.
1024Availability: \UNIX{}.
1025\end{funcdesc}
1026
1027\begin{funcdesc}{WSTOPSIG}{status}
Fred Drake35c3ffd1999-03-04 14:08:10 +00001028Return the signal which caused the process to stop.
1029Availability: \UNIX{}.
1030\end{funcdesc}
1031
1032\begin{funcdesc}{WTERMSIG}{status}
Fred Drake215fe2f1999-02-02 19:02:35 +00001033Return the signal which caused the process to exit.
1034Availability: \UNIX{}.
1035\end{funcdesc}
1036
1037
Thomas Woutersf8316632000-07-16 19:01:10 +00001038\subsection{Miscellaneous System Information \label{os-path}}
Fred Drake88f6ca21999-12-15 19:39:04 +00001039
1040
1041\begin{funcdesc}{confstr}{name}
1042Return string-valued system configuration values.
1043\var{name} specifies the configuration value to retrieve; it may be a
1044string which is the name of a defined system value; these names are
1045specified in a number of standards (\POSIX, Unix95, Unix98, and
1046others). Some platforms define additional names as well. The names
1047known to the host operating system are given in the
1048\code{confstr_names} dictionary. For configuration variables not
1049included in that mapping, passing an integer for \var{name} is also
1050accepted.
1051Availability: \UNIX{}.
1052
1053If the configuration value specified by \var{name} isn't defined, the
1054empty string is returned.
1055
1056If \var{name} is a string and is not known, \exception{ValueError} is
1057raised. If a specific value for \var{name} is not supported by the
1058host system, even if it is included in \code{confstr_names}, an
1059\exception{OSError} is raised with \constant{errno.EINVAL} for the
1060error number.
1061\end{funcdesc}
1062
1063\begin{datadesc}{confstr_names}
1064Dictionary mapping names accepted by \function{confstr()} to the
1065integer values defined for those names by the host operating system.
1066This can be used to determine the set of names known to the system.
1067Availability: \UNIX.
1068\end{datadesc}
1069
1070\begin{funcdesc}{sysconf}{name}
1071Return integer-valued system configuration values.
1072If the configuration value specified by \var{name} isn't defined,
1073\code{-1} is returned. The comments regarding the \var{name}
1074parameter for \function{confstr()} apply here as well; the dictionary
1075that provides information on the known names is given by
1076\code{sysconf_names}.
1077Availability: \UNIX{}.
1078\end{funcdesc}
1079
1080\begin{datadesc}{sysconf_names}
1081Dictionary mapping names accepted by \function{sysconf()} to the
1082integer values defined for those names by the host operating system.
1083This can be used to determine the set of names known to the system.
1084Availability: \UNIX.
1085\end{datadesc}
1086
Fred Drake215fe2f1999-02-02 19:02:35 +00001087
1088The follow data values are used to support path manipulation
1089operations. These are defined for all platforms.
1090
1091Higher-level operations on pathnames are defined in the
1092\refmodule{os.path} module.
1093
1094
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00001095\begin{datadesc}{curdir}
1096The constant string used by the OS to refer to the current directory,
Fred Drake1a3c2a01998-08-06 15:18:23 +00001097e.g.\ \code{'.'} for \POSIX{} or \code{':'} for the Macintosh.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00001098\end{datadesc}
1099
1100\begin{datadesc}{pardir}
1101The constant string used by the OS to refer to the parent directory,
Fred Drake1a3c2a01998-08-06 15:18:23 +00001102e.g.\ \code{'..'} for \POSIX{} or \code{'::'} for the Macintosh.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00001103\end{datadesc}
1104
1105\begin{datadesc}{sep}
Guido van Rossumb2afc811997-08-29 22:37:44 +00001106The character used by the OS to separate pathname components,
Fred Drake1a3c2a01998-08-06 15:18:23 +00001107e.g.\ \character{/} for \POSIX{} or \character{:} for the Macintosh.
1108Note that knowing this is not sufficient to be able to parse or
1109concatenate pathnames --- use \function{os.path.split()} and
1110\function{os.path.join()} --- but it is occasionally useful.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00001111\end{datadesc}
1112
Guido van Rossumb2afc811997-08-29 22:37:44 +00001113\begin{datadesc}{altsep}
1114An alternative character used by the OS to separate pathname components,
1115or \code{None} if only one separator character exists. This is set to
Fred Drake215fe2f1999-02-02 19:02:35 +00001116\character{/} on DOS and Windows systems where \code{sep} is a backslash.
Guido van Rossumb2afc811997-08-29 22:37:44 +00001117\end{datadesc}
1118
Guido van Rossum470be141995-03-17 16:07:09 +00001119\begin{datadesc}{pathsep}
1120The character conventionally used by the OS to separate search patch
Fred Drake1a3c2a01998-08-06 15:18:23 +00001121components (as in \envvar{PATH}), e.g.\ \character{:} for \POSIX{} or
Fred Drake215fe2f1999-02-02 19:02:35 +00001122\character{;} for DOS and Windows.
Guido van Rossum9c59ce91998-06-30 15:54:27 +00001123\end{datadesc}
1124
Guido van Rossum470be141995-03-17 16:07:09 +00001125\begin{datadesc}{defpath}
Fred Drake1a3c2a01998-08-06 15:18:23 +00001126The default search path used by \function{exec*p*()} if the environment
Guido van Rossum470be141995-03-17 16:07:09 +00001127doesn't have a \code{'PATH'} key.
1128\end{datadesc}
1129
Fred Drake215fe2f1999-02-02 19:02:35 +00001130\begin{datadesc}{linesep}
1131The string used to separate (or, rather, terminate) lines on the
Fred Drakeec6baaf1999-04-21 18:13:31 +00001132current platform. This may be a single character,
1133e.g.\ \code{'\e n'} for \POSIX{} or \code{'\e r'} for MacOS, or multiple
1134characters, e.g.\ \code{'\e r\e n'} for MS-DOS and MS Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +00001135\end{datadesc}