53
53
names have currently been registered: ``'posix'``, ``'nt'``,
54
54
``'os2'``, ``'ce'``, ``'java'``, ``'riscos'``.
57
:attr:`sys.platform` has a finer granularity. :func:`os.uname` gives
58
system-dependent version information.
60
The :mod:`platform` module provides detailed checks for the
88
95
On some platforms, including FreeBSD and Mac OS X, setting ``environ`` may
89
96
cause memory leaks. Refer to the system documentation for
92
99
If :func:`putenv` is not provided, a modified copy of this mapping may be
93
100
passed to the appropriate process-creation functions to cause child processes
303
310
.. function:: setpgrp()
305
Call the system call :cfunc:`setpgrp` or :cfunc:`setpgrp(0, 0)` depending on
312
Call the system call :c:func:`setpgrp` or :c:func:`setpgrp(0, 0)` depending on
306
313
which version is implemented (if any). See the Unix manual for the semantics.
308
315
Availability: Unix.
311
318
.. function:: setpgid(pid, pgrp)
313
Call the system call :cfunc:`setpgid` to set the process group id of the
320
Call the system call :c:func:`setpgid` to set the process group id of the
314
321
process with id *pid* to the process group with id *pgrp*. See the Unix manual
315
322
for the semantics.
378
385
.. function:: strerror(code)
380
387
Return the error message corresponding to the error code in *code*.
381
On platforms where :cfunc:`strerror` returns ``NULL`` when given an unknown
388
On platforms where :c:func:`strerror` returns ``NULL`` when given an unknown
382
389
error number, :exc:`ValueError` is raised.
384
391
Availability: Unix, Windows.
448
455
.. versionchanged:: 2.5
449
456
On Unix, when the *mode* argument starts with ``'a'``, the *O_APPEND* flag is
450
set on the file descriptor (which the :cfunc:`fdopen` implementation already
457
set on the file descriptor (which the :c:func:`fdopen` implementation already
451
458
does on most platforms).
471
478
.. versionchanged:: 2.0
472
479
This function worked unreliably under Windows in earlier versions of Python.
473
This was due to the use of the :cfunc:`_popen` function from the libraries
480
This was due to the use of the :c:func:`_popen` function from the libraries
474
481
provided with Windows. Newer versions of Python do not use the broken
475
482
implementation from the Windows libraries.
690
697
.. function:: fsync(fd)
692
699
Force write of file with filedescriptor *fd* to disk. On Unix, this calls the
693
native :cfunc:`fsync` function; on Windows, the MS :cfunc:`_commit` function.
700
native :c:func:`fsync` function; on Windows, the MS :c:func:`_commit` function.
695
702
If you're starting with a Python file object *f*, first do ``f.flush()``, and
696
703
then do ``os.fsync(f.fileno())``, to ensure that all internal buffers associated
1134
1143
.. function:: lstat(path)
1136
Perform the equivalent of an :cfunc:`lstat` system call on the given path.
1145
Perform the equivalent of an :c:func:`lstat` system call on the given path.
1137
1146
Similar to :func:`~os.stat`, but does not follow symbolic links. On
1138
1147
platforms that do not support symbolic links, this is an alias for
1139
1148
:func:`~os.stat`.
1171
1180
.. function:: major(device)
1173
1182
Extract the device major number from a raw device number (usually the
1174
:attr:`st_dev` or :attr:`st_rdev` field from :ctype:`stat`).
1183
:attr:`st_dev` or :attr:`st_rdev` field from :c:type:`stat`).
1176
1185
.. versionadded:: 2.3
1179
1188
.. function:: minor(device)
1181
1190
Extract the device minor number from a raw device number (usually the
1182
:attr:`st_dev` or :attr:`st_rdev` field from :ctype:`stat`).
1191
:attr:`st_dev` or :attr:`st_rdev` field from :c:type:`stat`).
1184
1193
.. versionadded:: 2.3
1335
1344
.. function:: stat(path)
1337
Perform the equivalent of a :cfunc:`stat` system call on the given path.
1346
Perform the equivalent of a :c:func:`stat` system call on the given path.
1338
1347
(This function follows symlinks; to stat a symlink use :func:`lstat`.)
1340
1349
The return value is an object whose attributes correspond to the members
1341
of the :ctype:`stat` structure, namely:
1350
of the :c:type:`stat` structure, namely:
1343
1352
* :attr:`st_mode` - protection bits,
1344
1353
* :attr:`st_ino` - inode number,
1389
The exact meaning and resolution of the :attr:`st_atime`, :attr:`st_mtime`, and
1390
:attr:`st_ctime` members depends on the operating system and the file system.
1391
For example, on Windows systems using the FAT or FAT32 file systems,
1392
:attr:`st_mtime` has 2-second resolution, and :attr:`st_atime` has only 1-day
1393
resolution. See your operating system documentation for details.
1398
The exact meaning and resolution of the :attr:`st_atime`,
1399
:attr:`st_mtime`, and :attr:`st_ctime` attributes depend on the operating
1400
system and the file system. For example, on Windows systems using the FAT
1401
or FAT32 file systems, :attr:`st_mtime` has 2-second resolution, and
1402
:attr:`st_atime` has only 1-day resolution. See your operating system
1403
documentation for details.
1395
1405
For backward compatibility, the return value of :func:`~os.stat` is also accessible
1396
1406
as a tuple of at least 10 integers giving the most important (and portable)
1397
members of the :ctype:`stat` structure, in the order :attr:`st_mode`,
1407
members of the :c:type:`stat` structure, in the order :attr:`st_mode`,
1398
1408
:attr:`st_ino`, :attr:`st_dev`, :attr:`st_nlink`, :attr:`st_uid`,
1399
1409
:attr:`st_gid`, :attr:`st_size`, :attr:`st_atime`, :attr:`st_mtime`,
1400
1410
:attr:`st_ctime`. More items may be added at the end by some implementations.
1402
1412
.. index:: module: stat
1404
1414
The standard module :mod:`stat` defines functions and constants that are useful
1405
for extracting information from a :ctype:`stat` structure. (On Windows, some
1415
for extracting information from a :c:type:`stat` structure. (On Windows, some
1406
1416
items are filled with dummy values.)
1452
1462
.. function:: statvfs(path)
1454
Perform a :cfunc:`statvfs` system call on the given path. The return value is
1464
Perform a :c:func:`statvfs` system call on the given path. The return value is
1455
1465
an object whose attributes describe the filesystem on the given path, and
1456
correspond to the members of the :ctype:`statvfs` structure, namely:
1466
correspond to the members of the :c:type:`statvfs` structure, namely:
1457
1467
:attr:`f_bsize`, :attr:`f_frsize`, :attr:`f_blocks`, :attr:`f_bfree`,
1458
1468
:attr:`f_bavail`, :attr:`f_files`, :attr:`f_ffree`, :attr:`f_favail`,
1459
1469
:attr:`f_flag`, :attr:`f_namemax`.
1463
1473
For backward compatibility, the return value is also accessible as a tuple whose
1464
1474
values correspond to the attributes, in the order given above. The standard
1465
1475
module :mod:`statvfs` defines constants that are useful for extracting
1466
information from a :ctype:`statvfs` structure when accessing it as a sequence;
1476
information from a :c:type:`statvfs` structure when accessing it as a sequence;
1467
1477
this remains useful when writing code that needs to work with versions of Python
1468
1478
that don't support accessing the fields as attributes.
1588
1598
ineffective, because in bottom-up mode the directories in *dirnames* are
1589
1599
generated before *dirpath* itself is generated.
1591
By default errors from the :func:`listdir` call are ignored. If optional
1601
By default, errors from the :func:`listdir` call are ignored. If optional
1592
1602
argument *onerror* is specified, it should be a function; it will be called with
1593
1603
one argument, an :exc:`OSError` instance. It can report the error to continue
1594
1604
with the walk, or raise the exception to abort the walk. Note that the filename
1654
1664
program loaded into the process. In each case, the first of these arguments is
1655
1665
passed to the new program as its own name rather than as an argument a user may
1656
1666
have typed on a command line. For the C programmer, this is the ``argv[0]``
1657
passed to a program's :cfunc:`main`. For example, ``os.execv('/bin/echo',
1667
passed to a program's :c:func:`main`. For example, ``os.execv('/bin/echo',
1658
1668
['foo', 'bar'])`` will only print ``bar`` on standard output; ``foo`` will seem
1664
1674
Generate a :const:`SIGABRT` signal to the current process. On Unix, the default
1665
1675
behavior is to produce a core dump; on Windows, the process immediately returns
1666
an exit code of ``3``. Be aware that programs which use :func:`signal.signal`
1667
to register a handler for :const:`SIGABRT` will behave differently.
1676
an exit code of ``3``. Be aware that calling this function will not call the
1677
Python signal handler registered for :const:`SIGABRT` with
1678
:func:`signal.signal`.
1669
1680
Availability: Unix, Windows.
2041
2052
os.spawnvpe(os.P_WAIT, 'cp', L, os.environ)
2043
2054
Availability: Unix, Windows. :func:`spawnlp`, :func:`spawnlpe`, :func:`spawnvp`
2044
and :func:`spawnvpe` are not available on Windows.
2055
and :func:`spawnvpe` are not available on Windows. :func:`spawnle` and
2056
:func:`spawnve` are not thread-safe on Windows; we advise you to use the
2057
:mod:`subprocess` module instead.
2046
2059
.. versionadded:: 1.6
2104
2117
There is no option to wait for the application to close, and no way to retrieve
2105
2118
the application's exit status. The *path* parameter is relative to the current
2106
2119
directory. If you want to use an absolute path, make sure the first character
2107
is not a slash (``'/'``); the underlying Win32 :cfunc:`ShellExecute` function
2120
is not a slash (``'/'``); the underlying Win32 :c:func:`ShellExecute` function
2108
2121
doesn't work if it is. Use the :func:`os.path.normpath` function to ensure that
2109
2122
the path is properly encoded for Win32.
2119
2132
.. function:: system(command)
2121
2134
Execute the command (a string) in a subshell. This is implemented by calling
2122
the Standard C function :cfunc:`system`, and has the same limitations.
2135
the Standard C function :c:func:`system`, and has the same limitations.
2123
2136
Changes to :data:`sys.stdin`, etc. are not reflected in the environment of the
2124
2137
executed command.
2126
2139
On Unix, the return value is the exit status of the process encoded in the
2127
2140
format specified for :func:`wait`. Note that POSIX does not specify the meaning
2128
of the return value of the C :cfunc:`system` function, so the return value of
2141
of the return value of the C :c:func:`system` function, so the return value of
2129
2142
the Python function is system-dependent.
2131
2144
On Windows, the return value is that returned by the system shell after running