Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
2 | <html> | |
3 | <head> | |
4 | <link rel="STYLESHEET" href="lib.css" type='text/css' /> | |
5 | <link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" /> | |
6 | <link rel='start' href='../index.html' title='Python Documentation Index' /> | |
7 | <link rel="first" href="lib.html" title='Python Library Reference' /> | |
8 | <link rel='contents' href='contents.html' title="Contents" /> | |
9 | <link rel='index' href='genindex.html' title='Index' /> | |
10 | <link rel='last' href='about.html' title='About this document...' /> | |
11 | <link rel='help' href='about.html' title='About this document...' /> | |
12 | <link rel="next" href="module-os.path.html" /> | |
13 | <link rel="prev" href="allos.html" /> | |
14 | <link rel="parent" href="allos.html" /> | |
15 | <link rel="next" href="os-procinfo.html" /> | |
16 | <meta name='aesop' content='information' /> | |
17 | <title>6.1 os -- Miscellaneous operating system interfaces</title> | |
18 | </head> | |
19 | <body> | |
20 | <DIV CLASS="navigation"> | |
21 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> | |
22 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
23 | <tr> | |
24 | <td class='online-navigation'><a rel="prev" title="6. Generic Operating System" | |
25 | href="allos.html"><img src='../icons/previous.png' | |
26 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
27 | <td class='online-navigation'><a rel="parent" title="6. Generic Operating System" | |
28 | href="allos.html"><img src='../icons/up.png' | |
29 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
30 | <td class='online-navigation'><a rel="next" title="6.1.1 Process Parameters" | |
31 | href="os-procinfo.html"><img src='../icons/next.png' | |
32 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
33 | <td align="center" width="100%">Python Library Reference</td> | |
34 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
35 | href="contents.html"><img src='../icons/contents.png' | |
36 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
37 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
38 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
39 | <td class='online-navigation'><a rel="index" title="Index" | |
40 | href="genindex.html"><img src='../icons/index.png' | |
41 | border='0' height='32' alt='Index' width='32' /></A></td> | |
42 | </tr></table> | |
43 | <div class='online-navigation'> | |
44 | <b class="navlabel">Previous:</b> | |
45 | <a class="sectref" rel="prev" href="allos.html">6. Generic Operating System</A> | |
46 | <b class="navlabel">Up:</b> | |
47 | <a class="sectref" rel="parent" href="allos.html">6. Generic Operating System</A> | |
48 | <b class="navlabel">Next:</b> | |
49 | <a class="sectref" rel="next" href="os-procinfo.html">6.1.1 Process Parameters</A> | |
50 | </div> | |
51 | <hr /></div> | |
52 | </DIV> | |
53 | <!--End of Navigation Panel--> | |
54 | ||
55 | <H1><A NAME="SECTION008100000000000000000"> | |
56 | 6.1 <tt class="module">os</tt> -- | |
57 | Miscellaneous operating system interfaces</A> | |
58 | </H1> | |
59 | ||
60 | <P> | |
61 | <A NAME="module-os"></A> | |
62 | ||
63 | <P> | |
64 | This module provides a more portable way of using operating system | |
65 | dependent functionality than importing a operating system dependent | |
66 | built-in module like <tt class="module"><a href="module-posix.html">posix</a></tt> or <tt class="module">nt</tt>. | |
67 | ||
68 | <P> | |
69 | This module searches for an operating system dependent built-in module like | |
70 | <tt class="module">mac</tt> or <tt class="module"><a href="module-posix.html">posix</a></tt> and exports the same functions and data | |
71 | as found there. The design of all Python's built-in operating system dependent | |
72 | modules is such that as long as the same functionality is available, | |
73 | it uses the same interface; for example, the function | |
74 | <code>os.stat(<var>path</var>)</code> returns stat information about <var>path</var> in | |
75 | the same format (which happens to have originated with the | |
76 | POSIX interface). | |
77 | ||
78 | <P> | |
79 | Extensions peculiar to a particular operating system are also | |
80 | available through the <tt class="module">os</tt> module, but using them is of course a | |
81 | threat to portability! | |
82 | ||
83 | <P> | |
84 | Note that after the first time <tt class="module">os</tt> is imported, there is | |
85 | <em>no</em> performance penalty in using functions from <tt class="module">os</tt> | |
86 | instead of directly from the operating system dependent built-in module, | |
87 | so there should be <em>no</em> reason not to use <tt class="module">os</tt>! | |
88 | ||
89 | <P> | |
90 | The <tt class="module">os</tt> module contains many functions and data values. | |
91 | The items below and in the following sub-sections are all available | |
92 | directly from the <tt class="module">os</tt> module. | |
93 | ||
94 | <P> | |
95 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-1504' xml:id='l2h-1504' class="exception">error</tt></b></dt> | |
96 | <dd> | |
97 | This exception is raised when a function returns a system-related | |
98 | error (not for illegal argument types or other incidental errors). | |
99 | This is also known as the built-in exception <tt class="exception">OSError</tt>. The | |
100 | accompanying value is a pair containing the numeric error code from | |
101 | <tt class="cdata">errno</tt> and the corresponding string, as would be printed by the | |
102 | C function <tt class="cfunction">perror()</tt>. See the module | |
103 | <tt class="module"><a href="module-errno.html">errno</a></tt><a id='l2h-1507' xml:id='l2h-1507'></a>, which contains names for the | |
104 | error codes defined by the underlying operating system. | |
105 | ||
106 | <P> | |
107 | When exceptions are classes, this exception carries two attributes, | |
108 | <tt class="member">errno</tt> and <tt class="member">strerror</tt>. The first holds the value of | |
109 | the C <tt class="cdata">errno</tt> variable, and the latter holds the corresponding | |
110 | error message from <tt class="cfunction">strerror()</tt>. For exceptions that | |
111 | involve a file system path (such as <tt class="function">chdir()</tt> or | |
112 | <tt class="function">unlink()</tt>), the exception instance will contain a third | |
113 | attribute, <tt class="member">filename</tt>, which is the file name passed to the | |
114 | function. | |
115 | </dd></dl> | |
116 | ||
117 | <P> | |
118 | <dl><dt><b><tt id='l2h-1505' xml:id='l2h-1505'>name</tt></b></dt> | |
119 | <dd> | |
120 | The name of the operating system dependent module imported. The | |
121 | following names have currently been registered: <code>'posix'</code>, | |
122 | <code>'nt'</code>, <code>'mac'</code>, <code>'os2'</code>, <code>'ce'</code>, | |
123 | <code>'java'</code>, <code>'riscos'</code>. | |
124 | </dd></dl> | |
125 | ||
126 | <P> | |
127 | <dl><dt><b><tt id='l2h-1506' xml:id='l2h-1506'>path</tt></b></dt> | |
128 | <dd> | |
129 | The corresponding operating system dependent standard module for pathname | |
130 | operations, such as <tt class="module">posixpath</tt> or <tt class="module">macpath</tt>. Thus, | |
131 | given the proper imports, <code>os.path.split(<var>file</var>)</code> is | |
132 | equivalent to but more portable than | |
133 | <code>posixpath.split(<var>file</var>)</code>. Note that this is also an | |
134 | importable module: it may be imported directly as | |
135 | <tt class="module"><a href="module-os.path.html">os.path</a></tt>. | |
136 | </dd></dl> | |
137 | ||
138 | <P> | |
139 | ||
140 | <p><br /></p><hr class='online-navigation' /> | |
141 | <div class='online-navigation'> | |
142 | <!--Table of Child-Links--> | |
143 | <A NAME="CHILD_LINKS"><STRONG>Subsections</STRONG></a> | |
144 | ||
145 | <UL CLASS="ChildLinks"> | |
146 | <LI><A href="os-procinfo.html">6.1.1 Process Parameters</a> | |
147 | <LI><A href="os-newstreams.html">6.1.2 File Object Creation</a> | |
148 | <LI><A href="os-fd-ops.html">6.1.3 File Descriptor Operations</a> | |
149 | <LI><A href="os-file-dir.html">6.1.4 Files and Directories</a> | |
150 | <LI><A href="os-process.html">6.1.5 Process Management</a> | |
151 | <LI><A href="os-path.html">6.1.6 Miscellaneous System Information</a> | |
152 | <LI><A href="os-miscfunc.html">6.1.7 Miscellaneous Functions</a> | |
153 | </ul> | |
154 | <!--End of Table of Child-Links--> | |
155 | </div> | |
156 | ||
157 | <DIV CLASS="navigation"> | |
158 | <div class='online-navigation'> | |
159 | <p></p><hr /> | |
160 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
161 | <tr> | |
162 | <td class='online-navigation'><a rel="prev" title="6. Generic Operating System" | |
163 | href="allos.html"><img src='../icons/previous.png' | |
164 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
165 | <td class='online-navigation'><a rel="parent" title="6. Generic Operating System" | |
166 | href="allos.html"><img src='../icons/up.png' | |
167 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
168 | <td class='online-navigation'><a rel="next" title="6.1.1 Process Parameters" | |
169 | href="os-procinfo.html"><img src='../icons/next.png' | |
170 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
171 | <td align="center" width="100%">Python Library Reference</td> | |
172 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
173 | href="contents.html"><img src='../icons/contents.png' | |
174 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
175 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
176 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
177 | <td class='online-navigation'><a rel="index" title="Index" | |
178 | href="genindex.html"><img src='../icons/index.png' | |
179 | border='0' height='32' alt='Index' width='32' /></A></td> | |
180 | </tr></table> | |
181 | <div class='online-navigation'> | |
182 | <b class="navlabel">Previous:</b> | |
183 | <a class="sectref" rel="prev" href="allos.html">6. Generic Operating System</A> | |
184 | <b class="navlabel">Up:</b> | |
185 | <a class="sectref" rel="parent" href="allos.html">6. Generic Operating System</A> | |
186 | <b class="navlabel">Next:</b> | |
187 | <a class="sectref" rel="next" href="os-procinfo.html">6.1.1 Process Parameters</A> | |
188 | </div> | |
189 | </div> | |
190 | <hr /> | |
191 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> | |
192 | </DIV> | |
193 | <!--End of Navigation Panel--> | |
194 | <ADDRESS> | |
195 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. | |
196 | </ADDRESS> | |
197 | </BODY> | |
198 | </HTML> |