|
1 | | - |
2 | 1 | :mod:`os` --- Miscellaneous operating system interfaces |
3 | 2 | ======================================================= |
4 | 3 |
|
5 | 4 | .. module:: os |
6 | 5 | :synopsis: Miscellaneous operating system interfaces. |
7 | 6 |
|
8 | 7 |
|
9 | | -This module provides a more portable way of using operating system dependent |
10 | | -functionality than importing an operating system dependent built-in module like |
11 | | -:mod:`posix` or :mod:`nt`. If you just want to read or write a file see |
12 | | -:func:`open`, if you want to manipulate paths, see the :mod:`os.path` |
13 | | -module, and if you want to read all the lines in all the files on the |
14 | | -command line see the :mod:`fileinput` module. For creating temporary |
15 | | -files and directories see the :mod:`tempfile` module, and for high-level |
16 | | -file and directory handling see the :mod:`shutil` module. |
17 | | - |
18 | | -This module searches for an operating system dependent built-in module like |
19 | | -:mod:`mac` or :mod:`posix` and exports the same functions and data as found |
20 | | -there. The design of all built-in operating system dependent modules of Python |
21 | | -is such that as long as the same functionality is available, it uses the same |
22 | | -interface; for example, the function ``os.stat(path)`` returns stat information |
23 | | -about *path* in the same format (which happens to have originated with the POSIX |
| 8 | +This module provides a portable way of using operating system dependent |
| 9 | +functionality. If you just want to read or write a file see :func:`open`, if |
| 10 | +you want to manipulate paths, see the :mod:`os.path` module, and if you want to |
| 11 | +read all the lines in all the files on the command line see the :mod:`fileinput` |
| 12 | +module. For creating temporary files and directories see the :mod:`tempfile` |
| 13 | +module, and for high-level file and directory handling see the :mod:`shutil` |
| 14 | +module. |
| 15 | + |
| 16 | +The design of all built-in operating system dependent modules of Python is such |
| 17 | +that as long as the same functionality is available, it uses the same interface; |
| 18 | +for example, the function ``os.stat(path)`` returns stat information about |
| 19 | +*path* in the same format (which happens to have originated with the POSIX |
24 | 20 | interface). |
25 | 21 |
|
26 | 22 | Extensions peculiar to a particular operating system are also available through |
27 | 23 | the :mod:`os` module, but using them is of course a threat to portability! |
28 | 24 |
|
29 | | -Note that after the first time :mod:`os` is imported, there is *no* performance |
30 | | -penalty in using functions from :mod:`os` instead of directly from the operating |
31 | | -system dependent built-in module, so there should be *no* reason not to use |
32 | | -:mod:`os`! |
| 25 | +.. note:: |
33 | 26 |
|
34 | | -The :mod:`os` module contains many functions and data values. The items below |
35 | | -and in the following sub-sections are all available directly from the :mod:`os` |
36 | | -module. |
| 27 | + All functions in this module raise :exc:`OSError` in the case of invalid or |
| 28 | + inaccessible file names and paths, or other arguments that have the correct |
| 29 | + type, but are not accepted by the operating system. |
37 | 30 |
|
38 | 31 | .. exception:: error |
39 | 32 |
|
40 | | - .. index:: module: errno |
41 | | - |
42 | | - This exception is raised when a function returns a system-related error (not for |
43 | | - illegal argument types or other incidental errors). This is also known as the |
44 | | - built-in exception :exc:`OSError`. The accompanying value is a pair containing |
45 | | - the numeric error code from :cdata:`errno` and the corresponding string, as |
46 | | - would be printed by the C function :cfunc:`perror`. See the module |
47 | | - :mod:`errno`, which contains names for the error codes defined by the underlying |
48 | | - operating system. |
49 | | - |
50 | | - When exceptions are classes, this exception carries two attributes, |
51 | | - :attr:`errno` and :attr:`strerror`. The first holds the value of the C |
52 | | - :cdata:`errno` variable, and the latter holds the corresponding error message |
53 | | - from :cfunc:`strerror`. For exceptions that involve a file system path (such as |
54 | | - :func:`chdir` or :func:`unlink`), the exception instance will contain a third |
55 | | - attribute, :attr:`filename`, which is the file name passed to the function. |
| 33 | + An alias for the built-in :exc:`OSError` exception. |
56 | 34 |
|
57 | 35 |
|
58 | 36 | .. data:: name |
@@ -645,7 +623,6 @@ platforms. For descriptions of their availability and use, consult |
645 | 623 | Files and Directories |
646 | 624 | --------------------- |
647 | 625 |
|
648 | | - |
649 | 626 | .. function:: access(path, mode) |
650 | 627 |
|
651 | 628 | Use the real uid/gid to test for access to *path*. Note that most operations |
@@ -1760,8 +1737,8 @@ Miscellaneous System Information |
1760 | 1737 |
|
1761 | 1738 | .. function:: getloadavg() |
1762 | 1739 |
|
1763 | | - Return the number of processes in the system run queue averaged over the last 1, |
1764 | | - 5, and 15 minutes or raises :exc:`OSError` if the load average was |
| 1740 | + Return the number of processes in the system run queue averaged over the last |
| 1741 | + 1, 5, and 15 minutes or raises :exc:`OSError` if the load average was |
1765 | 1742 | unobtainable. |
1766 | 1743 |
|
1767 | 1744 |
|
|
0 commit comments