~dkuhlman/python-training-materials/Materials

« back to all changes in this revision

Viewing changes to python-2.7.11-docs-html/library/os.html

  • Committer: Dave Kuhlman
  • Date: 2017-04-15 16:24:56 UTC
  • Revision ID: dkuhlman@davekuhlman.org-20170415162456-iav9vozzg4iwqwv3
Updated docs

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
 
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
 
 
4
 
 
5
 
<html xmlns="http://www.w3.org/1999/xhtml">
6
 
  <head>
7
 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
8
 
    
9
 
    <title>15.1. os — Miscellaneous operating system interfaces &mdash; Python 2.7.11 documentation</title>
10
 
    
11
 
    <link rel="stylesheet" href="../_static/classic.css" type="text/css" />
12
 
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
13
 
    
14
 
    <script type="text/javascript">
15
 
      var DOCUMENTATION_OPTIONS = {
16
 
        URL_ROOT:    '../',
17
 
        VERSION:     '2.7.11',
18
 
        COLLAPSE_INDEX: false,
19
 
        FILE_SUFFIX: '.html',
20
 
        HAS_SOURCE:  true
21
 
      };
22
 
    </script>
23
 
    <script type="text/javascript" src="../_static/jquery.js"></script>
24
 
    <script type="text/javascript" src="../_static/underscore.js"></script>
25
 
    <script type="text/javascript" src="../_static/doctools.js"></script>
26
 
    <script type="text/javascript" src="../_static/sidebar.js"></script>
27
 
    <link rel="search" type="application/opensearchdescription+xml"
28
 
          title="Search within Python 2.7.11 documentation"
29
 
          href="../_static/opensearch.xml"/>
30
 
    <link rel="author" title="About these documents" href="../about.html" />
31
 
    <link rel="copyright" title="Copyright" href="../copyright.html" />
32
 
    <link rel="top" title="Python 2.7.11 documentation" href="../contents.html" />
33
 
    <link rel="up" title="15. Generic Operating System Services" href="allos.html" />
34
 
    <link rel="next" title="15.2. io — Core tools for working with streams" href="io.html" />
35
 
    <link rel="prev" title="15. Generic Operating System Services" href="allos.html" />
36
 
    <link rel="shortcut icon" type="image/png" href="../_static/py.png" />
37
 
    <script type="text/javascript" src="../_static/copybutton.js"></script>
38
 
    <script type="text/javascript" src="../_static/version_switch.js"></script>
39
 
 
40
 
    
41
 
 
42
 
  </head>
43
 
  <body role="document">  
44
 
    <div class="related" role="navigation" aria-label="related navigation">
45
 
      <h3>Navigation</h3>
46
 
      <ul>
47
 
        <li class="right" style="margin-right: 10px">
48
 
          <a href="../genindex.html" title="General Index"
49
 
             accesskey="I">index</a></li>
50
 
        <li class="right" >
51
 
          <a href="../py-modindex.html" title="Python Module Index"
52
 
             >modules</a> |</li>
53
 
        <li class="right" >
54
 
          <a href="io.html" title="15.2. io — Core tools for working with streams"
55
 
             accesskey="N">next</a> |</li>
56
 
        <li class="right" >
57
 
          <a href="allos.html" title="15. Generic Operating System Services"
58
 
             accesskey="P">previous</a> |</li>
59
 
        <li><img src="../_static/py.png" alt=""
60
 
                 style="vertical-align: middle; margin-top: -1px"/></li>
61
 
        <li><a href="https://www.python.org/">Python</a> &raquo;</li>
62
 
        <li>
63
 
          <span class="version_switcher_placeholder">2.7.11</span>
64
 
          <a href="../index.html">Documentation</a> &raquo;
65
 
        </li>
66
 
 
67
 
          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &raquo;</li>
68
 
          <li class="nav-item nav-item-2"><a href="allos.html" accesskey="U">15. Generic Operating System Services</a> &raquo;</li> 
69
 
      </ul>
70
 
    </div>    
71
 
 
72
 
    <div class="document">
73
 
      <div class="documentwrapper">
74
 
        <div class="bodywrapper">
75
 
          <div class="body" role="main">
76
 
            
77
 
  <div class="section" id="module-os">
78
 
<span id="os-miscellaneous-operating-system-interfaces"></span><h1>15.1. <a class="reference internal" href="#module-os" title="os: Miscellaneous operating system interfaces."><code class="xref py py-mod docutils literal"><span class="pre">os</span></code></a> &#8212; Miscellaneous operating system interfaces<a class="headerlink" href="#module-os" title="Permalink to this headline">¶</a></h1>
79
 
<p>This module provides a portable way of using operating system dependent
80
 
functionality.  If you just want to read or write a file see <a class="reference internal" href="functions.html#open" title="open"><code class="xref py py-func docutils literal"><span class="pre">open()</span></code></a>, if
81
 
you want to manipulate paths, see the <a class="reference internal" href="os.path.html#module-os.path" title="os.path: Operations on pathnames."><code class="xref py py-mod docutils literal"><span class="pre">os.path</span></code></a> module, and if you want to
82
 
read all the lines in all the files on the command line see the <a class="reference internal" href="fileinput.html#module-fileinput" title="fileinput: Loop over standard input or a list of files."><code class="xref py py-mod docutils literal"><span class="pre">fileinput</span></code></a>
83
 
module.  For creating temporary files and directories see the <a class="reference internal" href="tempfile.html#module-tempfile" title="tempfile: Generate temporary files and directories."><code class="xref py py-mod docutils literal"><span class="pre">tempfile</span></code></a>
84
 
module, and for high-level file and directory handling see the <a class="reference internal" href="shutil.html#module-shutil" title="shutil: High-level file operations, including copying."><code class="xref py py-mod docutils literal"><span class="pre">shutil</span></code></a>
85
 
module.</p>
86
 
<p>Notes on the availability of these functions:</p>
87
 
<ul class="simple">
88
 
<li>The design of all built-in operating system dependent modules of Python is
89
 
such that as long as the same functionality is available, it uses the same
90
 
interface; for example, the function <code class="docutils literal"><span class="pre">os.stat(path)</span></code> returns stat
91
 
information about <em>path</em> in the same format (which happens to have originated
92
 
with the POSIX interface).</li>
93
 
<li>Extensions peculiar to a particular operating system are also available
94
 
through the <a class="reference internal" href="#module-os" title="os: Miscellaneous operating system interfaces."><code class="xref py py-mod docutils literal"><span class="pre">os</span></code></a> module, but using them is of course a threat to
95
 
portability.</li>
96
 
<li>An &#8220;Availability: Unix&#8221; note means that this function is commonly found on
97
 
Unix systems.  It does not make any claims about its existence on a specific
98
 
operating system.</li>
99
 
<li>If not separately noted, all functions that claim &#8220;Availability: Unix&#8221; are
100
 
supported on Mac OS X, which builds on a Unix core.</li>
101
 
</ul>
102
 
<div class="admonition note">
103
 
<p class="first admonition-title">Note</p>
104
 
<p class="last">All functions in this module raise <a class="reference internal" href="exceptions.html#exceptions.OSError" title="exceptions.OSError"><code class="xref py py-exc docutils literal"><span class="pre">OSError</span></code></a> in the case of invalid or
105
 
inaccessible file names and paths, or other arguments that have the correct
106
 
type, but are not accepted by the operating system.</p>
107
 
</div>
108
 
<dl class="exception">
109
 
<dt id="os.error">
110
 
<em class="property">exception </em><code class="descclassname">os.</code><code class="descname">error</code><a class="headerlink" href="#os.error" title="Permalink to this definition">¶</a></dt>
111
 
<dd><p>An alias for the built-in <a class="reference internal" href="exceptions.html#exceptions.OSError" title="exceptions.OSError"><code class="xref py py-exc docutils literal"><span class="pre">OSError</span></code></a> exception.</p>
112
 
</dd></dl>
113
 
 
114
 
<dl class="data">
115
 
<dt id="os.name">
116
 
<code class="descclassname">os.</code><code class="descname">name</code><a class="headerlink" href="#os.name" title="Permalink to this definition">¶</a></dt>
117
 
<dd><p>The name of the operating system dependent module imported.  The following
118
 
names have currently been registered: <code class="docutils literal"><span class="pre">'posix'</span></code>, <code class="docutils literal"><span class="pre">'nt'</span></code>,
119
 
<code class="docutils literal"><span class="pre">'os2'</span></code>, <code class="docutils literal"><span class="pre">'ce'</span></code>, <code class="docutils literal"><span class="pre">'java'</span></code>, <code class="docutils literal"><span class="pre">'riscos'</span></code>.</p>
120
 
<div class="admonition seealso">
121
 
<p class="first admonition-title">See also</p>
122
 
<p><a class="reference internal" href="sys.html#sys.platform" title="sys.platform"><code class="xref py py-attr docutils literal"><span class="pre">sys.platform</span></code></a> has a finer granularity.  <a class="reference internal" href="#os.uname" title="os.uname"><code class="xref py py-func docutils literal"><span class="pre">os.uname()</span></code></a> gives
123
 
system-dependent version information.</p>
124
 
<p class="last">The <a class="reference internal" href="platform.html#module-platform" title="platform: Retrieves as much platform identifying data as possible."><code class="xref py py-mod docutils literal"><span class="pre">platform</span></code></a> module provides detailed checks for the
125
 
system&#8217;s identity.</p>
126
 
</div>
127
 
</dd></dl>
128
 
 
129
 
<div class="section" id="process-parameters">
130
 
<span id="os-procinfo"></span><h2>15.1.1. Process Parameters<a class="headerlink" href="#process-parameters" title="Permalink to this headline">¶</a></h2>
131
 
<p>These functions and data items provide information and operate on the current
132
 
process and user.</p>
133
 
<dl class="data">
134
 
<dt id="os.environ">
135
 
<code class="descclassname">os.</code><code class="descname">environ</code><a class="headerlink" href="#os.environ" title="Permalink to this definition">¶</a></dt>
136
 
<dd><p>A <a class="reference internal" href="../glossary.html#term-mapping"><span class="xref std std-term">mapping</span></a> object representing the string environment. For example,
137
 
<code class="docutils literal"><span class="pre">environ['HOME']</span></code> is the pathname of your home directory (on some platforms),
138
 
and is equivalent to <code class="docutils literal"><span class="pre">getenv(&quot;HOME&quot;)</span></code> in C.</p>
139
 
<p>This mapping is captured the first time the <a class="reference internal" href="#module-os" title="os: Miscellaneous operating system interfaces."><code class="xref py py-mod docutils literal"><span class="pre">os</span></code></a> module is imported,
140
 
typically during Python startup as part of processing <code class="file docutils literal"><span class="pre">site.py</span></code>.  Changes
141
 
to the environment made after this time are not reflected in <code class="docutils literal"><span class="pre">os.environ</span></code>,
142
 
except for changes made by modifying <code class="docutils literal"><span class="pre">os.environ</span></code> directly.</p>
143
 
<p>If the platform supports the <a class="reference internal" href="#os.putenv" title="os.putenv"><code class="xref py py-func docutils literal"><span class="pre">putenv()</span></code></a> function, this mapping may be used
144
 
to modify the environment as well as query the environment.  <a class="reference internal" href="#os.putenv" title="os.putenv"><code class="xref py py-func docutils literal"><span class="pre">putenv()</span></code></a> will
145
 
be called automatically when the mapping is modified.</p>
146
 
<div class="admonition note">
147
 
<p class="first admonition-title">Note</p>
148
 
<p class="last">Calling <a class="reference internal" href="#os.putenv" title="os.putenv"><code class="xref py py-func docutils literal"><span class="pre">putenv()</span></code></a> directly does not change <code class="docutils literal"><span class="pre">os.environ</span></code>, so it&#8217;s better
149
 
to modify <code class="docutils literal"><span class="pre">os.environ</span></code>.</p>
150
 
</div>
151
 
<div class="admonition note">
152
 
<p class="first admonition-title">Note</p>
153
 
<p class="last">On some platforms, including FreeBSD and Mac OS X, setting <code class="docutils literal"><span class="pre">environ</span></code> may
154
 
cause memory leaks.  Refer to the system documentation for
155
 
<code class="xref c c-func docutils literal"><span class="pre">putenv()</span></code>.</p>
156
 
</div>
157
 
<p>If <a class="reference internal" href="#os.putenv" title="os.putenv"><code class="xref py py-func docutils literal"><span class="pre">putenv()</span></code></a> is not provided, a modified copy of this mapping  may be
158
 
passed to the appropriate process-creation functions to cause  child processes
159
 
to use a modified environment.</p>
160
 
<p>If the platform supports the <a class="reference internal" href="#os.unsetenv" title="os.unsetenv"><code class="xref py py-func docutils literal"><span class="pre">unsetenv()</span></code></a> function, you can delete items in
161
 
this mapping to unset environment variables. <a class="reference internal" href="#os.unsetenv" title="os.unsetenv"><code class="xref py py-func docutils literal"><span class="pre">unsetenv()</span></code></a> will be called
162
 
automatically when an item is deleted from <code class="docutils literal"><span class="pre">os.environ</span></code>, and when
163
 
one of the <code class="xref py py-meth docutils literal"><span class="pre">pop()</span></code> or <code class="xref py py-meth docutils literal"><span class="pre">clear()</span></code> methods is called.</p>
164
 
<div class="versionchanged">
165
 
<p><span class="versionmodified">Changed in version 2.6: </span>Also unset environment variables when calling <code class="xref py py-meth docutils literal"><span class="pre">os.environ.clear()</span></code>
166
 
and <code class="xref py py-meth docutils literal"><span class="pre">os.environ.pop()</span></code>.</p>
167
 
</div>
168
 
</dd></dl>
169
 
 
170
 
<dl class="function">
171
 
<dt>
172
 
<code class="descclassname">os.</code><code class="descname">chdir</code><span class="sig-paren">(</span><em>path</em><span class="sig-paren">)</span></dt>
173
 
<dt>
174
 
<code class="descclassname">os.</code><code class="descname">fchdir</code><span class="sig-paren">(</span><em>fd</em><span class="sig-paren">)</span></dt>
175
 
<dt>
176
 
<code class="descclassname">os.</code><code class="descname">getcwd</code><span class="sig-paren">(</span><span class="sig-paren">)</span></dt>
177
 
<dd><p>These functions are described in <a class="reference internal" href="#os-file-dir"><span>Files and Directories</span></a>.</p>
178
 
</dd></dl>
179
 
 
180
 
<dl class="function">
181
 
<dt id="os.ctermid">
182
 
<code class="descclassname">os.</code><code class="descname">ctermid</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.ctermid" title="Permalink to this definition">¶</a></dt>
183
 
<dd><p>Return the filename corresponding to the controlling terminal of the process.</p>
184
 
<p>Availability: Unix.</p>
185
 
</dd></dl>
186
 
 
187
 
<dl class="function">
188
 
<dt id="os.getegid">
189
 
<code class="descclassname">os.</code><code class="descname">getegid</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.getegid" title="Permalink to this definition">¶</a></dt>
190
 
<dd><p>Return the effective group id of the current process.  This corresponds to the
191
 
&#8220;set id&#8221; bit on the file being executed in the current process.</p>
192
 
<p>Availability: Unix.</p>
193
 
</dd></dl>
194
 
 
195
 
<dl class="function">
196
 
<dt id="os.geteuid">
197
 
<code class="descclassname">os.</code><code class="descname">geteuid</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.geteuid" title="Permalink to this definition">¶</a></dt>
198
 
<dd><p id="index-0">Return the current process&#8217;s effective user id.</p>
199
 
<p>Availability: Unix.</p>
200
 
</dd></dl>
201
 
 
202
 
<dl class="function">
203
 
<dt id="os.getgid">
204
 
<code class="descclassname">os.</code><code class="descname">getgid</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.getgid" title="Permalink to this definition">¶</a></dt>
205
 
<dd><p id="index-1">Return the real group id of the current process.</p>
206
 
<p>Availability: Unix.</p>
207
 
</dd></dl>
208
 
 
209
 
<dl class="function">
210
 
<dt id="os.getgroups">
211
 
<code class="descclassname">os.</code><code class="descname">getgroups</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.getgroups" title="Permalink to this definition">¶</a></dt>
212
 
<dd><p>Return list of supplemental group ids associated with the current process.</p>
213
 
<p>Availability: Unix.</p>
214
 
<div class="admonition note">
215
 
<p class="first admonition-title">Note</p>
216
 
<p class="last">On Mac OS X, <a class="reference internal" href="#os.getgroups" title="os.getgroups"><code class="xref py py-func docutils literal"><span class="pre">getgroups()</span></code></a> behavior differs somewhat from
217
 
other Unix platforms. If the Python interpreter was built with a
218
 
deployment target of <code class="xref py py-const docutils literal"><span class="pre">10.5</span></code> or earlier, <a class="reference internal" href="#os.getgroups" title="os.getgroups"><code class="xref py py-func docutils literal"><span class="pre">getgroups()</span></code></a> returns
219
 
the list of effective group ids associated with the current user process;
220
 
this list is limited to a system-defined number of entries, typically 16,
221
 
and may be modified by calls to <a class="reference internal" href="#os.setgroups" title="os.setgroups"><code class="xref py py-func docutils literal"><span class="pre">setgroups()</span></code></a> if suitably privileged.
222
 
If built with a deployment target greater than <code class="xref py py-const docutils literal"><span class="pre">10.5</span></code>,
223
 
<a class="reference internal" href="#os.getgroups" title="os.getgroups"><code class="xref py py-func docutils literal"><span class="pre">getgroups()</span></code></a> returns the current group access list for the user
224
 
associated with the effective user id of the process; the group access
225
 
list may change over the lifetime of the process, it is not affected by
226
 
calls to <a class="reference internal" href="#os.setgroups" title="os.setgroups"><code class="xref py py-func docutils literal"><span class="pre">setgroups()</span></code></a>, and its length is not limited to 16.  The
227
 
deployment target value, <code class="xref py py-const docutils literal"><span class="pre">MACOSX_DEPLOYMENT_TARGET</span></code>, can be
228
 
obtained with <a class="reference internal" href="sysconfig.html#sysconfig.get_config_var" title="sysconfig.get_config_var"><code class="xref py py-func docutils literal"><span class="pre">sysconfig.get_config_var()</span></code></a>.</p>
229
 
</div>
230
 
</dd></dl>
231
 
 
232
 
<dl class="function">
233
 
<dt id="os.initgroups">
234
 
<code class="descclassname">os.</code><code class="descname">initgroups</code><span class="sig-paren">(</span><em>username</em>, <em>gid</em><span class="sig-paren">)</span><a class="headerlink" href="#os.initgroups" title="Permalink to this definition">¶</a></dt>
235
 
<dd><p>Call the system initgroups() to initialize the group access list with all of
236
 
the groups of which the specified username is a member, plus the specified
237
 
group id.</p>
238
 
<p>Availability: Unix.</p>
239
 
<div class="versionadded">
240
 
<p><span class="versionmodified">New in version 2.7.</span></p>
241
 
</div>
242
 
</dd></dl>
243
 
 
244
 
<dl class="function">
245
 
<dt id="os.getlogin">
246
 
<code class="descclassname">os.</code><code class="descname">getlogin</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.getlogin" title="Permalink to this definition">¶</a></dt>
247
 
<dd><p>Return the name of the user logged in on the controlling terminal of the
248
 
process.  For most purposes, it is more useful to use the environment
249
 
variable <span class="target" id="index-2"></span><code class="xref std std-envvar docutils literal"><span class="pre">LOGNAME</span></code> to find out who the user is, or
250
 
<code class="docutils literal"><span class="pre">pwd.getpwuid(os.getuid())[0]</span></code> to get the login name of the process&#8217;s real
251
 
user id.</p>
252
 
<p>Availability: Unix.</p>
253
 
</dd></dl>
254
 
 
255
 
<dl class="function">
256
 
<dt id="os.getpgid">
257
 
<code class="descclassname">os.</code><code class="descname">getpgid</code><span class="sig-paren">(</span><em>pid</em><span class="sig-paren">)</span><a class="headerlink" href="#os.getpgid" title="Permalink to this definition">¶</a></dt>
258
 
<dd><p>Return the process group id of the process with process id <em>pid</em>. If <em>pid</em> is 0,
259
 
the process group id of the current process is returned.</p>
260
 
<p>Availability: Unix.</p>
261
 
<div class="versionadded">
262
 
<p><span class="versionmodified">New in version 2.3.</span></p>
263
 
</div>
264
 
</dd></dl>
265
 
 
266
 
<dl class="function">
267
 
<dt id="os.getpgrp">
268
 
<code class="descclassname">os.</code><code class="descname">getpgrp</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.getpgrp" title="Permalink to this definition">¶</a></dt>
269
 
<dd><p id="index-3">Return the id of the current process group.</p>
270
 
<p>Availability: Unix.</p>
271
 
</dd></dl>
272
 
 
273
 
<dl class="function">
274
 
<dt id="os.getpid">
275
 
<code class="descclassname">os.</code><code class="descname">getpid</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.getpid" title="Permalink to this definition">¶</a></dt>
276
 
<dd><p id="index-4">Return the current process id.</p>
277
 
<p>Availability: Unix, Windows.</p>
278
 
</dd></dl>
279
 
 
280
 
<dl class="function">
281
 
<dt id="os.getppid">
282
 
<code class="descclassname">os.</code><code class="descname">getppid</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.getppid" title="Permalink to this definition">¶</a></dt>
283
 
<dd><p id="index-5">Return the parent&#8217;s process id.</p>
284
 
<p>Availability: Unix.</p>
285
 
</dd></dl>
286
 
 
287
 
<dl class="function">
288
 
<dt id="os.getresuid">
289
 
<code class="descclassname">os.</code><code class="descname">getresuid</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.getresuid" title="Permalink to this definition">¶</a></dt>
290
 
<dd><p>Return a tuple (ruid, euid, suid) denoting the current process&#8217;s
291
 
real, effective, and saved user ids.</p>
292
 
<p>Availability: Unix.</p>
293
 
<div class="versionadded">
294
 
<p><span class="versionmodified">New in version 2.7.</span></p>
295
 
</div>
296
 
</dd></dl>
297
 
 
298
 
<dl class="function">
299
 
<dt id="os.getresgid">
300
 
<code class="descclassname">os.</code><code class="descname">getresgid</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.getresgid" title="Permalink to this definition">¶</a></dt>
301
 
<dd><p>Return a tuple (rgid, egid, sgid) denoting the current process&#8217;s
302
 
real, effective, and saved group ids.</p>
303
 
<p>Availability: Unix.</p>
304
 
<div class="versionadded">
305
 
<p><span class="versionmodified">New in version 2.7.</span></p>
306
 
</div>
307
 
</dd></dl>
308
 
 
309
 
<dl class="function">
310
 
<dt id="os.getuid">
311
 
<code class="descclassname">os.</code><code class="descname">getuid</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.getuid" title="Permalink to this definition">¶</a></dt>
312
 
<dd><p id="index-6">Return the current process&#8217;s real user id.</p>
313
 
<p>Availability: Unix.</p>
314
 
</dd></dl>
315
 
 
316
 
<dl class="function">
317
 
<dt id="os.getenv">
318
 
<code class="descclassname">os.</code><code class="descname">getenv</code><span class="sig-paren">(</span><em>varname</em><span class="optional">[</span>, <em>value</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#os.getenv" title="Permalink to this definition">¶</a></dt>
319
 
<dd><p>Return the value of the environment variable <em>varname</em> if it exists, or <em>value</em>
320
 
if it doesn&#8217;t.  <em>value</em> defaults to <code class="docutils literal"><span class="pre">None</span></code>.</p>
321
 
<p>Availability: most flavors of Unix, Windows.</p>
322
 
</dd></dl>
323
 
 
324
 
<dl class="function">
325
 
<dt id="os.putenv">
326
 
<code class="descclassname">os.</code><code class="descname">putenv</code><span class="sig-paren">(</span><em>varname</em>, <em>value</em><span class="sig-paren">)</span><a class="headerlink" href="#os.putenv" title="Permalink to this definition">¶</a></dt>
327
 
<dd><p id="index-7">Set the environment variable named <em>varname</em> to the string <em>value</em>.  Such
328
 
changes to the environment affect subprocesses started with <a class="reference internal" href="#os.system" title="os.system"><code class="xref py py-func docutils literal"><span class="pre">os.system()</span></code></a>,
329
 
<a class="reference internal" href="#os.popen" title="os.popen"><code class="xref py py-func docutils literal"><span class="pre">popen()</span></code></a> or <a class="reference internal" href="#os.fork" title="os.fork"><code class="xref py py-func docutils literal"><span class="pre">fork()</span></code></a> and <a class="reference internal" href="#os.execv" title="os.execv"><code class="xref py py-func docutils literal"><span class="pre">execv()</span></code></a>.</p>
330
 
<p>Availability: most flavors of Unix, Windows.</p>
331
 
<div class="admonition note">
332
 
<p class="first admonition-title">Note</p>
333
 
<p class="last">On some platforms, including FreeBSD and Mac OS X, setting <code class="docutils literal"><span class="pre">environ</span></code> may
334
 
cause memory leaks. Refer to the system documentation for putenv.</p>
335
 
</div>
336
 
<p>When <a class="reference internal" href="#os.putenv" title="os.putenv"><code class="xref py py-func docutils literal"><span class="pre">putenv()</span></code></a> is supported, assignments to items in <code class="docutils literal"><span class="pre">os.environ</span></code> are
337
 
automatically translated into corresponding calls to <a class="reference internal" href="#os.putenv" title="os.putenv"><code class="xref py py-func docutils literal"><span class="pre">putenv()</span></code></a>; however,
338
 
calls to <a class="reference internal" href="#os.putenv" title="os.putenv"><code class="xref py py-func docutils literal"><span class="pre">putenv()</span></code></a> don&#8217;t update <code class="docutils literal"><span class="pre">os.environ</span></code>, so it is actually
339
 
preferable to assign to items of <code class="docutils literal"><span class="pre">os.environ</span></code>.</p>
340
 
</dd></dl>
341
 
 
342
 
<dl class="function">
343
 
<dt id="os.setegid">
344
 
<code class="descclassname">os.</code><code class="descname">setegid</code><span class="sig-paren">(</span><em>egid</em><span class="sig-paren">)</span><a class="headerlink" href="#os.setegid" title="Permalink to this definition">¶</a></dt>
345
 
<dd><p>Set the current process&#8217;s effective group id.</p>
346
 
<p>Availability: Unix.</p>
347
 
</dd></dl>
348
 
 
349
 
<dl class="function">
350
 
<dt id="os.seteuid">
351
 
<code class="descclassname">os.</code><code class="descname">seteuid</code><span class="sig-paren">(</span><em>euid</em><span class="sig-paren">)</span><a class="headerlink" href="#os.seteuid" title="Permalink to this definition">¶</a></dt>
352
 
<dd><p>Set the current process&#8217;s effective user id.</p>
353
 
<p>Availability: Unix.</p>
354
 
</dd></dl>
355
 
 
356
 
<dl class="function">
357
 
<dt id="os.setgid">
358
 
<code class="descclassname">os.</code><code class="descname">setgid</code><span class="sig-paren">(</span><em>gid</em><span class="sig-paren">)</span><a class="headerlink" href="#os.setgid" title="Permalink to this definition">¶</a></dt>
359
 
<dd><p>Set the current process&#8217; group id.</p>
360
 
<p>Availability: Unix.</p>
361
 
</dd></dl>
362
 
 
363
 
<dl class="function">
364
 
<dt id="os.setgroups">
365
 
<code class="descclassname">os.</code><code class="descname">setgroups</code><span class="sig-paren">(</span><em>groups</em><span class="sig-paren">)</span><a class="headerlink" href="#os.setgroups" title="Permalink to this definition">¶</a></dt>
366
 
<dd><p>Set the list of supplemental group ids associated with the current process to
367
 
<em>groups</em>. <em>groups</em> must be a sequence, and each element must be an integer
368
 
identifying a group. This operation is typically available only to the superuser.</p>
369
 
<p>Availability: Unix.</p>
370
 
<div class="versionadded">
371
 
<p><span class="versionmodified">New in version 2.2.</span></p>
372
 
</div>
373
 
<div class="admonition note">
374
 
<p class="first admonition-title">Note</p>
375
 
<p class="last">On Mac OS X, the length of <em>groups</em> may not exceed the
376
 
system-defined maximum number of effective group ids, typically 16.
377
 
See the documentation for <a class="reference internal" href="#os.getgroups" title="os.getgroups"><code class="xref py py-func docutils literal"><span class="pre">getgroups()</span></code></a> for cases where it may not
378
 
return the same group list set by calling setgroups().</p>
379
 
</div>
380
 
</dd></dl>
381
 
 
382
 
<dl class="function">
383
 
<dt id="os.setpgrp">
384
 
<code class="descclassname">os.</code><code class="descname">setpgrp</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.setpgrp" title="Permalink to this definition">¶</a></dt>
385
 
<dd><p>Call the system call <code class="xref c c-func docutils literal"><span class="pre">setpgrp()</span></code> or <code class="xref c c-func docutils literal"><span class="pre">setpgrp(0,</span> <span class="pre">0)()</span></code> depending on
386
 
which version is implemented (if any).  See the Unix manual for the semantics.</p>
387
 
<p>Availability: Unix.</p>
388
 
</dd></dl>
389
 
 
390
 
<dl class="function">
391
 
<dt id="os.setpgid">
392
 
<code class="descclassname">os.</code><code class="descname">setpgid</code><span class="sig-paren">(</span><em>pid</em>, <em>pgrp</em><span class="sig-paren">)</span><a class="headerlink" href="#os.setpgid" title="Permalink to this definition">¶</a></dt>
393
 
<dd><p>Call the system call <code class="xref c c-func docutils literal"><span class="pre">setpgid()</span></code> to set the process group id of the
394
 
process with id <em>pid</em> to the process group with id <em>pgrp</em>.  See the Unix manual
395
 
for the semantics.</p>
396
 
<p>Availability: Unix.</p>
397
 
</dd></dl>
398
 
 
399
 
<dl class="function">
400
 
<dt id="os.setregid">
401
 
<code class="descclassname">os.</code><code class="descname">setregid</code><span class="sig-paren">(</span><em>rgid</em>, <em>egid</em><span class="sig-paren">)</span><a class="headerlink" href="#os.setregid" title="Permalink to this definition">¶</a></dt>
402
 
<dd><p>Set the current process&#8217;s real and effective group ids.</p>
403
 
<p>Availability: Unix.</p>
404
 
</dd></dl>
405
 
 
406
 
<dl class="function">
407
 
<dt id="os.setresgid">
408
 
<code class="descclassname">os.</code><code class="descname">setresgid</code><span class="sig-paren">(</span><em>rgid</em>, <em>egid</em>, <em>sgid</em><span class="sig-paren">)</span><a class="headerlink" href="#os.setresgid" title="Permalink to this definition">¶</a></dt>
409
 
<dd><p>Set the current process&#8217;s real, effective, and saved group ids.</p>
410
 
<p>Availability: Unix.</p>
411
 
<div class="versionadded">
412
 
<p><span class="versionmodified">New in version 2.7.</span></p>
413
 
</div>
414
 
</dd></dl>
415
 
 
416
 
<dl class="function">
417
 
<dt id="os.setresuid">
418
 
<code class="descclassname">os.</code><code class="descname">setresuid</code><span class="sig-paren">(</span><em>ruid</em>, <em>euid</em>, <em>suid</em><span class="sig-paren">)</span><a class="headerlink" href="#os.setresuid" title="Permalink to this definition">¶</a></dt>
419
 
<dd><p>Set the current process&#8217;s real, effective, and saved user ids.</p>
420
 
<p>Availability: Unix.</p>
421
 
<div class="versionadded">
422
 
<p><span class="versionmodified">New in version 2.7.</span></p>
423
 
</div>
424
 
</dd></dl>
425
 
 
426
 
<dl class="function">
427
 
<dt id="os.setreuid">
428
 
<code class="descclassname">os.</code><code class="descname">setreuid</code><span class="sig-paren">(</span><em>ruid</em>, <em>euid</em><span class="sig-paren">)</span><a class="headerlink" href="#os.setreuid" title="Permalink to this definition">¶</a></dt>
429
 
<dd><p>Set the current process&#8217;s real and effective user ids.</p>
430
 
<p>Availability: Unix.</p>
431
 
</dd></dl>
432
 
 
433
 
<dl class="function">
434
 
<dt id="os.getsid">
435
 
<code class="descclassname">os.</code><code class="descname">getsid</code><span class="sig-paren">(</span><em>pid</em><span class="sig-paren">)</span><a class="headerlink" href="#os.getsid" title="Permalink to this definition">¶</a></dt>
436
 
<dd><p>Call the system call <code class="xref c c-func docutils literal"><span class="pre">getsid()</span></code>.  See the Unix manual for the semantics.</p>
437
 
<p>Availability: Unix.</p>
438
 
<div class="versionadded">
439
 
<p><span class="versionmodified">New in version 2.4.</span></p>
440
 
</div>
441
 
</dd></dl>
442
 
 
443
 
<dl class="function">
444
 
<dt id="os.setsid">
445
 
<code class="descclassname">os.</code><code class="descname">setsid</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.setsid" title="Permalink to this definition">¶</a></dt>
446
 
<dd><p>Call the system call <code class="xref c c-func docutils literal"><span class="pre">setsid()</span></code>.  See the Unix manual for the semantics.</p>
447
 
<p>Availability: Unix.</p>
448
 
</dd></dl>
449
 
 
450
 
<dl class="function">
451
 
<dt id="os.setuid">
452
 
<code class="descclassname">os.</code><code class="descname">setuid</code><span class="sig-paren">(</span><em>uid</em><span class="sig-paren">)</span><a class="headerlink" href="#os.setuid" title="Permalink to this definition">¶</a></dt>
453
 
<dd><p id="index-8">Set the current process&#8217;s user id.</p>
454
 
<p>Availability: Unix.</p>
455
 
</dd></dl>
456
 
 
457
 
<dl class="function">
458
 
<dt id="os.strerror">
459
 
<code class="descclassname">os.</code><code class="descname">strerror</code><span class="sig-paren">(</span><em>code</em><span class="sig-paren">)</span><a class="headerlink" href="#os.strerror" title="Permalink to this definition">¶</a></dt>
460
 
<dd><p>Return the error message corresponding to the error code in <em>code</em>.
461
 
On platforms where <code class="xref c c-func docutils literal"><span class="pre">strerror()</span></code> returns <code class="docutils literal"><span class="pre">NULL</span></code> when given an unknown
462
 
error number, <a class="reference internal" href="exceptions.html#exceptions.ValueError" title="exceptions.ValueError"><code class="xref py py-exc docutils literal"><span class="pre">ValueError</span></code></a> is raised.</p>
463
 
<p>Availability: Unix, Windows.</p>
464
 
</dd></dl>
465
 
 
466
 
<dl class="function">
467
 
<dt id="os.umask">
468
 
<code class="descclassname">os.</code><code class="descname">umask</code><span class="sig-paren">(</span><em>mask</em><span class="sig-paren">)</span><a class="headerlink" href="#os.umask" title="Permalink to this definition">¶</a></dt>
469
 
<dd><p>Set the current numeric umask and return the previous umask.</p>
470
 
<p>Availability: Unix, Windows.</p>
471
 
</dd></dl>
472
 
 
473
 
<dl class="function">
474
 
<dt id="os.uname">
475
 
<code class="descclassname">os.</code><code class="descname">uname</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.uname" title="Permalink to this definition">¶</a></dt>
476
 
<dd><p id="index-9">Return a 5-tuple containing information identifying the current operating
477
 
system.  The tuple contains 5 strings: <code class="docutils literal"><span class="pre">(sysname,</span> <span class="pre">nodename,</span> <span class="pre">release,</span> <span class="pre">version,</span>
478
 
<span class="pre">machine)</span></code>.  Some systems truncate the nodename to 8 characters or to the
479
 
leading component; a better way to get the hostname is
480
 
<a class="reference internal" href="socket.html#socket.gethostname" title="socket.gethostname"><code class="xref py py-func docutils literal"><span class="pre">socket.gethostname()</span></code></a>  or even
481
 
<code class="docutils literal"><span class="pre">socket.gethostbyaddr(socket.gethostname())</span></code>.</p>
482
 
<p>Availability: recent flavors of Unix.</p>
483
 
</dd></dl>
484
 
 
485
 
<dl class="function">
486
 
<dt id="os.unsetenv">
487
 
<code class="descclassname">os.</code><code class="descname">unsetenv</code><span class="sig-paren">(</span><em>varname</em><span class="sig-paren">)</span><a class="headerlink" href="#os.unsetenv" title="Permalink to this definition">¶</a></dt>
488
 
<dd><p id="index-10">Unset (delete) the environment variable named <em>varname</em>. Such changes to the
489
 
environment affect subprocesses started with <a class="reference internal" href="#os.system" title="os.system"><code class="xref py py-func docutils literal"><span class="pre">os.system()</span></code></a>, <a class="reference internal" href="#os.popen" title="os.popen"><code class="xref py py-func docutils literal"><span class="pre">popen()</span></code></a> or
490
 
<a class="reference internal" href="#os.fork" title="os.fork"><code class="xref py py-func docutils literal"><span class="pre">fork()</span></code></a> and <a class="reference internal" href="#os.execv" title="os.execv"><code class="xref py py-func docutils literal"><span class="pre">execv()</span></code></a>.</p>
491
 
<p>When <a class="reference internal" href="#os.unsetenv" title="os.unsetenv"><code class="xref py py-func docutils literal"><span class="pre">unsetenv()</span></code></a> is supported, deletion of items in <code class="docutils literal"><span class="pre">os.environ</span></code> is
492
 
automatically translated into a corresponding call to <a class="reference internal" href="#os.unsetenv" title="os.unsetenv"><code class="xref py py-func docutils literal"><span class="pre">unsetenv()</span></code></a>; however,
493
 
calls to <a class="reference internal" href="#os.unsetenv" title="os.unsetenv"><code class="xref py py-func docutils literal"><span class="pre">unsetenv()</span></code></a> don&#8217;t update <code class="docutils literal"><span class="pre">os.environ</span></code>, so it is actually
494
 
preferable to delete items of <code class="docutils literal"><span class="pre">os.environ</span></code>.</p>
495
 
<p>Availability: most flavors of Unix, Windows.</p>
496
 
</dd></dl>
497
 
 
498
 
</div>
499
 
<div class="section" id="file-object-creation">
500
 
<span id="os-newstreams"></span><h2>15.1.2. File Object Creation<a class="headerlink" href="#file-object-creation" title="Permalink to this headline">¶</a></h2>
501
 
<p>These functions create new file objects. (See also <a class="reference internal" href="functions.html#open" title="open"><code class="xref py py-func docutils literal"><span class="pre">open()</span></code></a>.)</p>
502
 
<dl class="function">
503
 
<dt id="os.fdopen">
504
 
<code class="descclassname">os.</code><code class="descname">fdopen</code><span class="sig-paren">(</span><em>fd</em><span class="optional">[</span>, <em>mode</em><span class="optional">[</span>, <em>bufsize</em><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#os.fdopen" title="Permalink to this definition">¶</a></dt>
505
 
<dd><p id="index-11">Return an open file object connected to the file descriptor <em>fd</em>.  The <em>mode</em>
506
 
and <em>bufsize</em> arguments have the same meaning as the corresponding arguments
507
 
to the built-in <a class="reference internal" href="functions.html#open" title="open"><code class="xref py py-func docutils literal"><span class="pre">open()</span></code></a> function.  If <a class="reference internal" href="#os.fdopen" title="os.fdopen"><code class="xref py py-func docutils literal"><span class="pre">fdopen()</span></code></a> raises an
508
 
exception, it leaves <em>fd</em> untouched (unclosed).</p>
509
 
<p>Availability: Unix, Windows.</p>
510
 
<div class="versionchanged">
511
 
<p><span class="versionmodified">Changed in version 2.3: </span>When specified, the <em>mode</em> argument must now start with one of the letters
512
 
<code class="docutils literal"><span class="pre">'r'</span></code>, <code class="docutils literal"><span class="pre">'w'</span></code>, or <code class="docutils literal"><span class="pre">'a'</span></code>, otherwise a <a class="reference internal" href="exceptions.html#exceptions.ValueError" title="exceptions.ValueError"><code class="xref py py-exc docutils literal"><span class="pre">ValueError</span></code></a> is raised.</p>
513
 
</div>
514
 
<div class="versionchanged">
515
 
<p><span class="versionmodified">Changed in version 2.5: </span>On Unix, when the <em>mode</em> argument starts with <code class="docutils literal"><span class="pre">'a'</span></code>, the <em>O_APPEND</em> flag is
516
 
set on the file descriptor (which the <code class="xref c c-func docutils literal"><span class="pre">fdopen()</span></code> implementation already
517
 
does on most platforms).</p>
518
 
</div>
519
 
</dd></dl>
520
 
 
521
 
<dl class="function">
522
 
<dt id="os.popen">
523
 
<code class="descclassname">os.</code><code class="descname">popen</code><span class="sig-paren">(</span><em>command</em><span class="optional">[</span>, <em>mode</em><span class="optional">[</span>, <em>bufsize</em><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#os.popen" title="Permalink to this definition">¶</a></dt>
524
 
<dd><p>Open a pipe to or from <em>command</em>.  The return value is an open file object
525
 
connected to the pipe, which can be read or written depending on whether <em>mode</em>
526
 
is <code class="docutils literal"><span class="pre">'r'</span></code> (default) or <code class="docutils literal"><span class="pre">'w'</span></code>. The <em>bufsize</em> argument has the same meaning as
527
 
the corresponding argument to the built-in <a class="reference internal" href="functions.html#open" title="open"><code class="xref py py-func docutils literal"><span class="pre">open()</span></code></a> function.  The exit
528
 
status of the command (encoded in the format specified for <a class="reference internal" href="#os.wait" title="os.wait"><code class="xref py py-func docutils literal"><span class="pre">wait()</span></code></a>) is
529
 
available as the return value of the <a class="reference internal" href="stdtypes.html#file.close" title="file.close"><code class="xref py py-meth docutils literal"><span class="pre">close()</span></code></a> method of the file object,
530
 
except that when the exit status is zero (termination without errors), <code class="docutils literal"><span class="pre">None</span></code>
531
 
is returned.</p>
532
 
<p>Availability: Unix, Windows.</p>
533
 
<div class="deprecated">
534
 
<p><span class="versionmodified">Deprecated since version 2.6: </span>This function is obsolete.  Use the <a class="reference internal" href="subprocess.html#module-subprocess" title="subprocess: Subprocess management."><code class="xref py py-mod docutils literal"><span class="pre">subprocess</span></code></a> module.  Check
535
 
especially the <a class="reference internal" href="subprocess.html#subprocess-replacements"><span>Replacing Older Functions with the subprocess Module</span></a> section.</p>
536
 
</div>
537
 
<div class="versionchanged">
538
 
<p><span class="versionmodified">Changed in version 2.0: </span>This function worked unreliably under Windows in earlier versions of Python.
539
 
This was due to the use of the <code class="xref c c-func docutils literal"><span class="pre">_popen()</span></code> function from the libraries
540
 
provided with Windows.  Newer versions of Python do not use the broken
541
 
implementation from the Windows libraries.</p>
542
 
</div>
543
 
</dd></dl>
544
 
 
545
 
<dl class="function">
546
 
<dt id="os.tmpfile">
547
 
<code class="descclassname">os.</code><code class="descname">tmpfile</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.tmpfile" title="Permalink to this definition">¶</a></dt>
548
 
<dd><p>Return a new file object opened in update mode (<code class="docutils literal"><span class="pre">w+b</span></code>).  The file has no
549
 
directory entries associated with it and will be automatically deleted once
550
 
there are no file descriptors for the file.</p>
551
 
<p>Availability: Unix, Windows.</p>
552
 
</dd></dl>
553
 
 
554
 
<p>There are a number of different <code class="xref py py-func docutils literal"><span class="pre">popen*()</span></code> functions that provide slightly
555
 
different ways to create subprocesses.</p>
556
 
<div class="deprecated">
557
 
<p><span class="versionmodified">Deprecated since version 2.6: </span>All of the <code class="xref py py-func docutils literal"><span class="pre">popen*()</span></code> functions are obsolete. Use the <a class="reference internal" href="subprocess.html#module-subprocess" title="subprocess: Subprocess management."><code class="xref py py-mod docutils literal"><span class="pre">subprocess</span></code></a>
558
 
module.</p>
559
 
</div>
560
 
<p>For each of the <code class="xref py py-func docutils literal"><span class="pre">popen*()</span></code> variants, if <em>bufsize</em> is specified, it
561
 
specifies the buffer size for the I/O pipes. <em>mode</em>, if provided, should be the
562
 
string <code class="docutils literal"><span class="pre">'b'</span></code> or <code class="docutils literal"><span class="pre">'t'</span></code>; on Windows this is needed to determine whether the
563
 
file objects should be opened in binary or text mode.  The default value for
564
 
<em>mode</em> is <code class="docutils literal"><span class="pre">'t'</span></code>.</p>
565
 
<p>Also, for each of these variants, on Unix, <em>cmd</em> may be a sequence, in which
566
 
case arguments will be passed directly to the program without shell intervention
567
 
(as with <a class="reference internal" href="#os.spawnv" title="os.spawnv"><code class="xref py py-func docutils literal"><span class="pre">os.spawnv()</span></code></a>). If <em>cmd</em> is a string it will be passed to the shell
568
 
(as with <a class="reference internal" href="#os.system" title="os.system"><code class="xref py py-func docutils literal"><span class="pre">os.system()</span></code></a>).</p>
569
 
<p>These methods do not make it possible to retrieve the exit status from the child
570
 
processes.  The only way to control the input and output streams and also
571
 
retrieve the return codes is to use the <a class="reference internal" href="subprocess.html#module-subprocess" title="subprocess: Subprocess management."><code class="xref py py-mod docutils literal"><span class="pre">subprocess</span></code></a> module; these are only
572
 
available on Unix.</p>
573
 
<p>For a discussion of possible deadlock conditions related to the use of these
574
 
functions, see <a class="reference internal" href="popen2.html#popen2-flow-control"><span>Flow Control Issues</span></a>.</p>
575
 
<dl class="function">
576
 
<dt id="os.popen2">
577
 
<code class="descclassname">os.</code><code class="descname">popen2</code><span class="sig-paren">(</span><em>cmd</em><span class="optional">[</span>, <em>mode</em><span class="optional">[</span>, <em>bufsize</em><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#os.popen2" title="Permalink to this definition">¶</a></dt>
578
 
<dd><p>Execute <em>cmd</em> as a sub-process and return the file objects <code class="docutils literal"><span class="pre">(child_stdin,</span>
579
 
<span class="pre">child_stdout)</span></code>.</p>
580
 
<div class="deprecated">
581
 
<p><span class="versionmodified">Deprecated since version 2.6: </span>This function is obsolete.  Use the <a class="reference internal" href="subprocess.html#module-subprocess" title="subprocess: Subprocess management."><code class="xref py py-mod docutils literal"><span class="pre">subprocess</span></code></a> module.  Check
582
 
especially the <a class="reference internal" href="subprocess.html#subprocess-replacements"><span>Replacing Older Functions with the subprocess Module</span></a> section.</p>
583
 
</div>
584
 
<p>Availability: Unix, Windows.</p>
585
 
<div class="versionadded">
586
 
<p><span class="versionmodified">New in version 2.0.</span></p>
587
 
</div>
588
 
</dd></dl>
589
 
 
590
 
<dl class="function">
591
 
<dt id="os.popen3">
592
 
<code class="descclassname">os.</code><code class="descname">popen3</code><span class="sig-paren">(</span><em>cmd</em><span class="optional">[</span>, <em>mode</em><span class="optional">[</span>, <em>bufsize</em><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#os.popen3" title="Permalink to this definition">¶</a></dt>
593
 
<dd><p>Execute <em>cmd</em> as a sub-process and return the file objects <code class="docutils literal"><span class="pre">(child_stdin,</span>
594
 
<span class="pre">child_stdout,</span> <span class="pre">child_stderr)</span></code>.</p>
595
 
<div class="deprecated">
596
 
<p><span class="versionmodified">Deprecated since version 2.6: </span>This function is obsolete.  Use the <a class="reference internal" href="subprocess.html#module-subprocess" title="subprocess: Subprocess management."><code class="xref py py-mod docutils literal"><span class="pre">subprocess</span></code></a> module.  Check
597
 
especially the <a class="reference internal" href="subprocess.html#subprocess-replacements"><span>Replacing Older Functions with the subprocess Module</span></a> section.</p>
598
 
</div>
599
 
<p>Availability: Unix, Windows.</p>
600
 
<div class="versionadded">
601
 
<p><span class="versionmodified">New in version 2.0.</span></p>
602
 
</div>
603
 
</dd></dl>
604
 
 
605
 
<dl class="function">
606
 
<dt id="os.popen4">
607
 
<code class="descclassname">os.</code><code class="descname">popen4</code><span class="sig-paren">(</span><em>cmd</em><span class="optional">[</span>, <em>mode</em><span class="optional">[</span>, <em>bufsize</em><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#os.popen4" title="Permalink to this definition">¶</a></dt>
608
 
<dd><p>Execute <em>cmd</em> as a sub-process and return the file objects <code class="docutils literal"><span class="pre">(child_stdin,</span>
609
 
<span class="pre">child_stdout_and_stderr)</span></code>.</p>
610
 
<div class="deprecated">
611
 
<p><span class="versionmodified">Deprecated since version 2.6: </span>This function is obsolete.  Use the <a class="reference internal" href="subprocess.html#module-subprocess" title="subprocess: Subprocess management."><code class="xref py py-mod docutils literal"><span class="pre">subprocess</span></code></a> module.  Check
612
 
especially the <a class="reference internal" href="subprocess.html#subprocess-replacements"><span>Replacing Older Functions with the subprocess Module</span></a> section.</p>
613
 
</div>
614
 
<p>Availability: Unix, Windows.</p>
615
 
<div class="versionadded">
616
 
<p><span class="versionmodified">New in version 2.0.</span></p>
617
 
</div>
618
 
</dd></dl>
619
 
 
620
 
<p>(Note that <code class="docutils literal"><span class="pre">child_stdin,</span> <span class="pre">child_stdout,</span> <span class="pre">and</span> <span class="pre">child_stderr</span></code> are named from the
621
 
point of view of the child process, so <em>child_stdin</em> is the child&#8217;s standard
622
 
input.)</p>
623
 
<p>This functionality is also available in the <a class="reference internal" href="popen2.html#module-popen2" title="popen2: Subprocesses with accessible standard I/O streams. (deprecated)"><code class="xref py py-mod docutils literal"><span class="pre">popen2</span></code></a> module using functions
624
 
of the same names, but the return values of those functions have a different
625
 
order.</p>
626
 
</div>
627
 
<div class="section" id="file-descriptor-operations">
628
 
<span id="os-fd-ops"></span><h2>15.1.3. File Descriptor Operations<a class="headerlink" href="#file-descriptor-operations" title="Permalink to this headline">¶</a></h2>
629
 
<p>These functions operate on I/O streams referenced using file descriptors.</p>
630
 
<p>File descriptors are small integers corresponding to a file that has been opened
631
 
by the current process.  For example, standard input is usually file descriptor
632
 
0, standard output is 1, and standard error is 2.  Further files opened by a
633
 
process will then be assigned 3, 4, 5, and so forth.  The name &#8220;file descriptor&#8221;
634
 
is slightly deceptive; on Unix platforms, sockets and pipes are also referenced
635
 
by file descriptors.</p>
636
 
<p>The <a class="reference internal" href="stdtypes.html#file.fileno" title="file.fileno"><code class="xref py py-meth docutils literal"><span class="pre">fileno()</span></code></a> method can be used to obtain the file descriptor
637
 
associated with a file object when required.  Note that using the file
638
 
descriptor directly will bypass the file object methods, ignoring aspects such
639
 
as internal buffering of data.</p>
640
 
<dl class="function">
641
 
<dt id="os.close">
642
 
<code class="descclassname">os.</code><code class="descname">close</code><span class="sig-paren">(</span><em>fd</em><span class="sig-paren">)</span><a class="headerlink" href="#os.close" title="Permalink to this definition">¶</a></dt>
643
 
<dd><p>Close file descriptor <em>fd</em>.</p>
644
 
<p>Availability: Unix, Windows.</p>
645
 
<div class="admonition note">
646
 
<p class="first admonition-title">Note</p>
647
 
<p class="last">This function is intended for low-level I/O and must be applied to a file
648
 
descriptor as returned by <a class="reference internal" href="#os.open" title="os.open"><code class="xref py py-func docutils literal"><span class="pre">os.open()</span></code></a> or <a class="reference internal" href="#os.pipe" title="os.pipe"><code class="xref py py-func docutils literal"><span class="pre">pipe()</span></code></a>.  To close a &#8220;file
649
 
object&#8221; returned by the built-in function <a class="reference internal" href="functions.html#open" title="open"><code class="xref py py-func docutils literal"><span class="pre">open()</span></code></a> or by <a class="reference internal" href="#os.popen" title="os.popen"><code class="xref py py-func docutils literal"><span class="pre">popen()</span></code></a> or
650
 
<a class="reference internal" href="#os.fdopen" title="os.fdopen"><code class="xref py py-func docutils literal"><span class="pre">fdopen()</span></code></a>, use its <a class="reference internal" href="io.html#io.IOBase.close" title="io.IOBase.close"><code class="xref py py-meth docutils literal"><span class="pre">close()</span></code></a> method.</p>
651
 
</div>
652
 
</dd></dl>
653
 
 
654
 
<dl class="function">
655
 
<dt id="os.closerange">
656
 
<code class="descclassname">os.</code><code class="descname">closerange</code><span class="sig-paren">(</span><em>fd_low</em>, <em>fd_high</em><span class="sig-paren">)</span><a class="headerlink" href="#os.closerange" title="Permalink to this definition">¶</a></dt>
657
 
<dd><p>Close all file descriptors from <em>fd_low</em> (inclusive) to <em>fd_high</em> (exclusive),
658
 
ignoring errors. Equivalent to:</p>
659
 
<div class="highlight-python"><div class="highlight"><pre><span class="k">for</span> <span class="n">fd</span> <span class="ow">in</span> <span class="nb">xrange</span><span class="p">(</span><span class="n">fd_low</span><span class="p">,</span> <span class="n">fd_high</span><span class="p">):</span>
660
 
    <span class="k">try</span><span class="p">:</span>
661
 
        <span class="n">os</span><span class="o">.</span><span class="n">close</span><span class="p">(</span><span class="n">fd</span><span class="p">)</span>
662
 
    <span class="k">except</span> <span class="ne">OSError</span><span class="p">:</span>
663
 
        <span class="k">pass</span>
664
 
</pre></div>
665
 
</div>
666
 
<p>Availability: Unix, Windows.</p>
667
 
<div class="versionadded">
668
 
<p><span class="versionmodified">New in version 2.6.</span></p>
669
 
</div>
670
 
</dd></dl>
671
 
 
672
 
<dl class="function">
673
 
<dt id="os.dup">
674
 
<code class="descclassname">os.</code><code class="descname">dup</code><span class="sig-paren">(</span><em>fd</em><span class="sig-paren">)</span><a class="headerlink" href="#os.dup" title="Permalink to this definition">¶</a></dt>
675
 
<dd><p>Return a duplicate of file descriptor <em>fd</em>.</p>
676
 
<p>Availability: Unix, Windows.</p>
677
 
</dd></dl>
678
 
 
679
 
<dl class="function">
680
 
<dt id="os.dup2">
681
 
<code class="descclassname">os.</code><code class="descname">dup2</code><span class="sig-paren">(</span><em>fd</em>, <em>fd2</em><span class="sig-paren">)</span><a class="headerlink" href="#os.dup2" title="Permalink to this definition">¶</a></dt>
682
 
<dd><p>Duplicate file descriptor <em>fd</em> to <em>fd2</em>, closing the latter first if necessary.</p>
683
 
<p>Availability: Unix, Windows.</p>
684
 
</dd></dl>
685
 
 
686
 
<dl class="function">
687
 
<dt id="os.fchmod">
688
 
<code class="descclassname">os.</code><code class="descname">fchmod</code><span class="sig-paren">(</span><em>fd</em>, <em>mode</em><span class="sig-paren">)</span><a class="headerlink" href="#os.fchmod" title="Permalink to this definition">¶</a></dt>
689
 
<dd><p>Change the mode of the file given by <em>fd</em> to the numeric <em>mode</em>.  See the docs
690
 
for <a class="reference internal" href="#os.chmod" title="os.chmod"><code class="xref py py-func docutils literal"><span class="pre">chmod()</span></code></a> for possible values of <em>mode</em>.</p>
691
 
<p>Availability: Unix.</p>
692
 
<div class="versionadded">
693
 
<p><span class="versionmodified">New in version 2.6.</span></p>
694
 
</div>
695
 
</dd></dl>
696
 
 
697
 
<dl class="function">
698
 
<dt id="os.fchown">
699
 
<code class="descclassname">os.</code><code class="descname">fchown</code><span class="sig-paren">(</span><em>fd</em>, <em>uid</em>, <em>gid</em><span class="sig-paren">)</span><a class="headerlink" href="#os.fchown" title="Permalink to this definition">¶</a></dt>
700
 
<dd><p>Change the owner and group id of the file given by <em>fd</em> to the numeric <em>uid</em>
701
 
and <em>gid</em>.  To leave one of the ids unchanged, set it to -1.</p>
702
 
<p>Availability: Unix.</p>
703
 
<div class="versionadded">
704
 
<p><span class="versionmodified">New in version 2.6.</span></p>
705
 
</div>
706
 
</dd></dl>
707
 
 
708
 
<dl class="function">
709
 
<dt id="os.fdatasync">
710
 
<code class="descclassname">os.</code><code class="descname">fdatasync</code><span class="sig-paren">(</span><em>fd</em><span class="sig-paren">)</span><a class="headerlink" href="#os.fdatasync" title="Permalink to this definition">¶</a></dt>
711
 
<dd><p>Force write of file with filedescriptor <em>fd</em> to disk. Does not force update of
712
 
metadata.</p>
713
 
<p>Availability: Unix.</p>
714
 
<div class="admonition note">
715
 
<p class="first admonition-title">Note</p>
716
 
<p class="last">This function is not available on MacOS.</p>
717
 
</div>
718
 
</dd></dl>
719
 
 
720
 
<dl class="function">
721
 
<dt id="os.fpathconf">
722
 
<code class="descclassname">os.</code><code class="descname">fpathconf</code><span class="sig-paren">(</span><em>fd</em>, <em>name</em><span class="sig-paren">)</span><a class="headerlink" href="#os.fpathconf" title="Permalink to this definition">¶</a></dt>
723
 
<dd><p>Return system configuration information relevant to an open file. <em>name</em>
724
 
specifies the configuration value to retrieve; it may be a string which is the
725
 
name of a defined system value; these names are specified in a number of
726
 
standards (POSIX.1, Unix 95, Unix 98, and others).  Some platforms define
727
 
additional names as well.  The names known to the host operating system are
728
 
given in the <code class="docutils literal"><span class="pre">pathconf_names</span></code> dictionary.  For configuration variables not
729
 
included in that mapping, passing an integer for <em>name</em> is also accepted.</p>
730
 
<p>If <em>name</em> is a string and is not known, <a class="reference internal" href="exceptions.html#exceptions.ValueError" title="exceptions.ValueError"><code class="xref py py-exc docutils literal"><span class="pre">ValueError</span></code></a> is raised.  If a
731
 
specific value for <em>name</em> is not supported by the host system, even if it is
732
 
included in <code class="docutils literal"><span class="pre">pathconf_names</span></code>, an <a class="reference internal" href="exceptions.html#exceptions.OSError" title="exceptions.OSError"><code class="xref py py-exc docutils literal"><span class="pre">OSError</span></code></a> is raised with
733
 
<a class="reference internal" href="errno.html#errno.EINVAL" title="errno.EINVAL"><code class="xref py py-const docutils literal"><span class="pre">errno.EINVAL</span></code></a> for the error number.</p>
734
 
<p>Availability: Unix.</p>
735
 
</dd></dl>
736
 
 
737
 
<dl class="function">
738
 
<dt id="os.fstat">
739
 
<code class="descclassname">os.</code><code class="descname">fstat</code><span class="sig-paren">(</span><em>fd</em><span class="sig-paren">)</span><a class="headerlink" href="#os.fstat" title="Permalink to this definition">¶</a></dt>
740
 
<dd><p>Return status for file descriptor <em>fd</em>, like <a class="reference internal" href="#os.stat" title="os.stat"><code class="xref py py-func docutils literal"><span class="pre">stat()</span></code></a>.</p>
741
 
<p>Availability: Unix, Windows.</p>
742
 
</dd></dl>
743
 
 
744
 
<dl class="function">
745
 
<dt id="os.fstatvfs">
746
 
<code class="descclassname">os.</code><code class="descname">fstatvfs</code><span class="sig-paren">(</span><em>fd</em><span class="sig-paren">)</span><a class="headerlink" href="#os.fstatvfs" title="Permalink to this definition">¶</a></dt>
747
 
<dd><p>Return information about the filesystem containing the file associated with file
748
 
descriptor <em>fd</em>, like <a class="reference internal" href="statvfs.html#module-statvfs" title="statvfs: Constants for interpreting the result of os.statvfs(). (deprecated)"><code class="xref py py-func docutils literal"><span class="pre">statvfs()</span></code></a>.</p>
749
 
<p>Availability: Unix.</p>
750
 
</dd></dl>
751
 
 
752
 
<dl class="function">
753
 
<dt id="os.fsync">
754
 
<code class="descclassname">os.</code><code class="descname">fsync</code><span class="sig-paren">(</span><em>fd</em><span class="sig-paren">)</span><a class="headerlink" href="#os.fsync" title="Permalink to this definition">¶</a></dt>
755
 
<dd><p>Force write of file with filedescriptor <em>fd</em> to disk.  On Unix, this calls the
756
 
native <code class="xref c c-func docutils literal"><span class="pre">fsync()</span></code> function; on Windows, the MS <code class="xref c c-func docutils literal"><span class="pre">_commit()</span></code> function.</p>
757
 
<p>If you&#8217;re starting with a Python file object <em>f</em>, first do <code class="docutils literal"><span class="pre">f.flush()</span></code>, and
758
 
then do <code class="docutils literal"><span class="pre">os.fsync(f.fileno())</span></code>, to ensure that all internal buffers associated
759
 
with <em>f</em> are written to disk.</p>
760
 
<p>Availability: Unix, and Windows starting in 2.2.3.</p>
761
 
</dd></dl>
762
 
 
763
 
<dl class="function">
764
 
<dt id="os.ftruncate">
765
 
<code class="descclassname">os.</code><code class="descname">ftruncate</code><span class="sig-paren">(</span><em>fd</em>, <em>length</em><span class="sig-paren">)</span><a class="headerlink" href="#os.ftruncate" title="Permalink to this definition">¶</a></dt>
766
 
<dd><p>Truncate the file corresponding to file descriptor <em>fd</em>, so that it is at most
767
 
<em>length</em> bytes in size.</p>
768
 
<p>Availability: Unix.</p>
769
 
</dd></dl>
770
 
 
771
 
<dl class="function">
772
 
<dt id="os.isatty">
773
 
<code class="descclassname">os.</code><code class="descname">isatty</code><span class="sig-paren">(</span><em>fd</em><span class="sig-paren">)</span><a class="headerlink" href="#os.isatty" title="Permalink to this definition">¶</a></dt>
774
 
<dd><p>Return <code class="docutils literal"><span class="pre">True</span></code> if the file descriptor <em>fd</em> is open and connected to a
775
 
tty(-like) device, else <code class="docutils literal"><span class="pre">False</span></code>.</p>
776
 
</dd></dl>
777
 
 
778
 
<dl class="function">
779
 
<dt id="os.lseek">
780
 
<code class="descclassname">os.</code><code class="descname">lseek</code><span class="sig-paren">(</span><em>fd</em>, <em>pos</em>, <em>how</em><span class="sig-paren">)</span><a class="headerlink" href="#os.lseek" title="Permalink to this definition">¶</a></dt>
781
 
<dd><p>Set the current position of file descriptor <em>fd</em> to position <em>pos</em>, modified
782
 
by <em>how</em>: <a class="reference internal" href="#os.SEEK_SET" title="os.SEEK_SET"><code class="xref py py-const docutils literal"><span class="pre">SEEK_SET</span></code></a> or <code class="docutils literal"><span class="pre">0</span></code> to set the position relative to the
783
 
beginning of the file; <a class="reference internal" href="#os.SEEK_CUR" title="os.SEEK_CUR"><code class="xref py py-const docutils literal"><span class="pre">SEEK_CUR</span></code></a> or <code class="docutils literal"><span class="pre">1</span></code> to set it relative to the
784
 
current position; <a class="reference internal" href="#os.SEEK_END" title="os.SEEK_END"><code class="xref py py-const docutils literal"><span class="pre">SEEK_END</span></code></a> or <code class="docutils literal"><span class="pre">2</span></code> to set it relative to the end of
785
 
the file. Return the new cursor position in bytes, starting from the beginning.</p>
786
 
<p>Availability: Unix, Windows.</p>
787
 
</dd></dl>
788
 
 
789
 
<dl class="data">
790
 
<dt id="os.SEEK_SET">
791
 
<code class="descclassname">os.</code><code class="descname">SEEK_SET</code><a class="headerlink" href="#os.SEEK_SET" title="Permalink to this definition">¶</a></dt>
792
 
<dt id="os.SEEK_CUR">
793
 
<code class="descclassname">os.</code><code class="descname">SEEK_CUR</code><a class="headerlink" href="#os.SEEK_CUR" title="Permalink to this definition">¶</a></dt>
794
 
<dt id="os.SEEK_END">
795
 
<code class="descclassname">os.</code><code class="descname">SEEK_END</code><a class="headerlink" href="#os.SEEK_END" title="Permalink to this definition">¶</a></dt>
796
 
<dd><p>Parameters to the <a class="reference internal" href="#os.lseek" title="os.lseek"><code class="xref py py-func docutils literal"><span class="pre">lseek()</span></code></a> function. Their values are 0, 1, and 2,
797
 
respectively.</p>
798
 
<p>Availability: Windows, Unix.</p>
799
 
<div class="versionadded">
800
 
<p><span class="versionmodified">New in version 2.5.</span></p>
801
 
</div>
802
 
</dd></dl>
803
 
 
804
 
<dl class="function">
805
 
<dt id="os.open">
806
 
<code class="descclassname">os.</code><code class="descname">open</code><span class="sig-paren">(</span><em>file</em>, <em>flags</em><span class="optional">[</span>, <em>mode</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#os.open" title="Permalink to this definition">¶</a></dt>
807
 
<dd><p>Open the file <em>file</em> and set various flags according to <em>flags</em> and possibly its
808
 
mode according to <em>mode</em>. The default <em>mode</em> is <code class="docutils literal"><span class="pre">0777</span></code> (octal), and the
809
 
current umask value is first masked out.  Return the file descriptor for the
810
 
newly opened file.</p>
811
 
<p>For a description of the flag and mode values, see the C run-time documentation;
812
 
flag constants (like <a class="reference internal" href="#os.O_RDONLY" title="os.O_RDONLY"><code class="xref py py-const docutils literal"><span class="pre">O_RDONLY</span></code></a> and <a class="reference internal" href="#os.O_WRONLY" title="os.O_WRONLY"><code class="xref py py-const docutils literal"><span class="pre">O_WRONLY</span></code></a>) are defined in
813
 
this module too (see <a class="reference internal" href="#open-constants"><span>open() flag constants</span></a>).  In particular, on Windows adding
814
 
<a class="reference internal" href="#os.O_BINARY" title="os.O_BINARY"><code class="xref py py-const docutils literal"><span class="pre">O_BINARY</span></code></a> is needed to open files in binary mode.</p>
815
 
<p>Availability: Unix, Windows.</p>
816
 
<div class="admonition note">
817
 
<p class="first admonition-title">Note</p>
818
 
<p class="last">This function is intended for low-level I/O.  For normal usage, use the
819
 
built-in function <a class="reference internal" href="functions.html#open" title="open"><code class="xref py py-func docutils literal"><span class="pre">open()</span></code></a>, which returns a &#8220;file object&#8221; with
820
 
<a class="reference internal" href="stdtypes.html#file.read" title="file.read"><code class="xref py py-meth docutils literal"><span class="pre">read()</span></code></a> and <a class="reference internal" href="stdtypes.html#file.write" title="file.write"><code class="xref py py-meth docutils literal"><span class="pre">write()</span></code></a> methods (and many more).  To
821
 
wrap a file descriptor in a &#8220;file object&#8221;, use <a class="reference internal" href="#os.fdopen" title="os.fdopen"><code class="xref py py-func docutils literal"><span class="pre">fdopen()</span></code></a>.</p>
822
 
</div>
823
 
</dd></dl>
824
 
 
825
 
<dl class="function">
826
 
<dt id="os.openpty">
827
 
<code class="descclassname">os.</code><code class="descname">openpty</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.openpty" title="Permalink to this definition">¶</a></dt>
828
 
<dd><p id="index-12">Open a new pseudo-terminal pair. Return a pair of file descriptors <code class="docutils literal"><span class="pre">(master,</span>
829
 
<span class="pre">slave)</span></code> for the pty and the tty, respectively. For a (slightly) more portable
830
 
approach, use the <a class="reference internal" href="pty.html#module-pty" title="pty: Pseudo-Terminal Handling for Linux. (Linux)"><code class="xref py py-mod docutils literal"><span class="pre">pty</span></code></a> module.</p>
831
 
<p>Availability: some flavors of Unix.</p>
832
 
</dd></dl>
833
 
 
834
 
<dl class="function">
835
 
<dt id="os.pipe">
836
 
<code class="descclassname">os.</code><code class="descname">pipe</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.pipe" title="Permalink to this definition">¶</a></dt>
837
 
<dd><p>Create a pipe.  Return a pair of file descriptors <code class="docutils literal"><span class="pre">(r,</span> <span class="pre">w)</span></code> usable for reading
838
 
and writing, respectively.</p>
839
 
<p>Availability: Unix, Windows.</p>
840
 
</dd></dl>
841
 
 
842
 
<dl class="function">
843
 
<dt id="os.read">
844
 
<code class="descclassname">os.</code><code class="descname">read</code><span class="sig-paren">(</span><em>fd</em>, <em>n</em><span class="sig-paren">)</span><a class="headerlink" href="#os.read" title="Permalink to this definition">¶</a></dt>
845
 
<dd><p>Read at most <em>n</em> bytes from file descriptor <em>fd</em>. Return a string containing the
846
 
bytes read.  If the end of the file referred to by <em>fd</em> has been reached, an
847
 
empty string is returned.</p>
848
 
<p>Availability: Unix, Windows.</p>
849
 
<div class="admonition note">
850
 
<p class="first admonition-title">Note</p>
851
 
<p class="last">This function is intended for low-level I/O and must be applied to a file
852
 
descriptor as returned by <a class="reference internal" href="#os.open" title="os.open"><code class="xref py py-func docutils literal"><span class="pre">os.open()</span></code></a> or <a class="reference internal" href="#os.pipe" title="os.pipe"><code class="xref py py-func docutils literal"><span class="pre">pipe()</span></code></a>.  To read a &#8220;file object&#8221;
853
 
returned by the built-in function <a class="reference internal" href="functions.html#open" title="open"><code class="xref py py-func docutils literal"><span class="pre">open()</span></code></a> or by <a class="reference internal" href="#os.popen" title="os.popen"><code class="xref py py-func docutils literal"><span class="pre">popen()</span></code></a> or
854
 
<a class="reference internal" href="#os.fdopen" title="os.fdopen"><code class="xref py py-func docutils literal"><span class="pre">fdopen()</span></code></a>, or <a class="reference internal" href="sys.html#sys.stdin" title="sys.stdin"><code class="xref py py-data docutils literal"><span class="pre">sys.stdin</span></code></a>, use its <a class="reference internal" href="stdtypes.html#file.read" title="file.read"><code class="xref py py-meth docutils literal"><span class="pre">read()</span></code></a> or
855
 
<a class="reference internal" href="stdtypes.html#file.readline" title="file.readline"><code class="xref py py-meth docutils literal"><span class="pre">readline()</span></code></a> methods.</p>
856
 
</div>
857
 
</dd></dl>
858
 
 
859
 
<dl class="function">
860
 
<dt id="os.tcgetpgrp">
861
 
<code class="descclassname">os.</code><code class="descname">tcgetpgrp</code><span class="sig-paren">(</span><em>fd</em><span class="sig-paren">)</span><a class="headerlink" href="#os.tcgetpgrp" title="Permalink to this definition">¶</a></dt>
862
 
<dd><p>Return the process group associated with the terminal given by <em>fd</em> (an open
863
 
file descriptor as returned by <a class="reference internal" href="#os.open" title="os.open"><code class="xref py py-func docutils literal"><span class="pre">os.open()</span></code></a>).</p>
864
 
<p>Availability: Unix.</p>
865
 
</dd></dl>
866
 
 
867
 
<dl class="function">
868
 
<dt id="os.tcsetpgrp">
869
 
<code class="descclassname">os.</code><code class="descname">tcsetpgrp</code><span class="sig-paren">(</span><em>fd</em>, <em>pg</em><span class="sig-paren">)</span><a class="headerlink" href="#os.tcsetpgrp" title="Permalink to this definition">¶</a></dt>
870
 
<dd><p>Set the process group associated with the terminal given by <em>fd</em> (an open file
871
 
descriptor as returned by <a class="reference internal" href="#os.open" title="os.open"><code class="xref py py-func docutils literal"><span class="pre">os.open()</span></code></a>) to <em>pg</em>.</p>
872
 
<p>Availability: Unix.</p>
873
 
</dd></dl>
874
 
 
875
 
<dl class="function">
876
 
<dt id="os.ttyname">
877
 
<code class="descclassname">os.</code><code class="descname">ttyname</code><span class="sig-paren">(</span><em>fd</em><span class="sig-paren">)</span><a class="headerlink" href="#os.ttyname" title="Permalink to this definition">¶</a></dt>
878
 
<dd><p>Return a string which specifies the terminal device associated with
879
 
file descriptor <em>fd</em>.  If <em>fd</em> is not associated with a terminal device, an
880
 
exception is raised.</p>
881
 
<p>Availability: Unix.</p>
882
 
</dd></dl>
883
 
 
884
 
<dl class="function">
885
 
<dt id="os.write">
886
 
<code class="descclassname">os.</code><code class="descname">write</code><span class="sig-paren">(</span><em>fd</em>, <em>str</em><span class="sig-paren">)</span><a class="headerlink" href="#os.write" title="Permalink to this definition">¶</a></dt>
887
 
<dd><p>Write the string <em>str</em> to file descriptor <em>fd</em>. Return the number of bytes
888
 
actually written.</p>
889
 
<p>Availability: Unix, Windows.</p>
890
 
<div class="admonition note">
891
 
<p class="first admonition-title">Note</p>
892
 
<p class="last">This function is intended for low-level I/O and must be applied to a file
893
 
descriptor as returned by <a class="reference internal" href="#os.open" title="os.open"><code class="xref py py-func docutils literal"><span class="pre">os.open()</span></code></a> or <a class="reference internal" href="#os.pipe" title="os.pipe"><code class="xref py py-func docutils literal"><span class="pre">pipe()</span></code></a>.  To write a &#8220;file
894
 
object&#8221; returned by the built-in function <a class="reference internal" href="functions.html#open" title="open"><code class="xref py py-func docutils literal"><span class="pre">open()</span></code></a> or by <a class="reference internal" href="#os.popen" title="os.popen"><code class="xref py py-func docutils literal"><span class="pre">popen()</span></code></a> or
895
 
<a class="reference internal" href="#os.fdopen" title="os.fdopen"><code class="xref py py-func docutils literal"><span class="pre">fdopen()</span></code></a>, or <a class="reference internal" href="sys.html#sys.stdout" title="sys.stdout"><code class="xref py py-data docutils literal"><span class="pre">sys.stdout</span></code></a> or <a class="reference internal" href="sys.html#sys.stderr" title="sys.stderr"><code class="xref py py-data docutils literal"><span class="pre">sys.stderr</span></code></a>, use its
896
 
<a class="reference internal" href="stdtypes.html#file.write" title="file.write"><code class="xref py py-meth docutils literal"><span class="pre">write()</span></code></a> method.</p>
897
 
</div>
898
 
</dd></dl>
899
 
 
900
 
<div class="section" id="open-flag-constants">
901
 
<span id="open-constants"></span><h3>15.1.3.1. <code class="docutils literal"><span class="pre">open()</span></code> flag constants<a class="headerlink" href="#open-flag-constants" title="Permalink to this headline">¶</a></h3>
902
 
<p>The following constants are options for the <em>flags</em> parameter to the
903
 
<a class="reference internal" href="#os.open" title="os.open"><code class="xref py py-func docutils literal"><span class="pre">open()</span></code></a> function.  They can be combined using the bitwise OR operator
904
 
<code class="docutils literal"><span class="pre">|</span></code>.  Some of them are not available on all platforms.  For descriptions of
905
 
their availability and use, consult the <em class="manpage">open(2)</em> manual page on Unix
906
 
or <a class="reference external" href="http://msdn.microsoft.com/en-us/library/z0kc8e3z.aspx">the MSDN</a> on Windows.</p>
907
 
<dl class="data">
908
 
<dt id="os.O_RDONLY">
909
 
<code class="descclassname">os.</code><code class="descname">O_RDONLY</code><a class="headerlink" href="#os.O_RDONLY" title="Permalink to this definition">¶</a></dt>
910
 
<dt id="os.O_WRONLY">
911
 
<code class="descclassname">os.</code><code class="descname">O_WRONLY</code><a class="headerlink" href="#os.O_WRONLY" title="Permalink to this definition">¶</a></dt>
912
 
<dt id="os.O_RDWR">
913
 
<code class="descclassname">os.</code><code class="descname">O_RDWR</code><a class="headerlink" href="#os.O_RDWR" title="Permalink to this definition">¶</a></dt>
914
 
<dt id="os.O_APPEND">
915
 
<code class="descclassname">os.</code><code class="descname">O_APPEND</code><a class="headerlink" href="#os.O_APPEND" title="Permalink to this definition">¶</a></dt>
916
 
<dt id="os.O_CREAT">
917
 
<code class="descclassname">os.</code><code class="descname">O_CREAT</code><a class="headerlink" href="#os.O_CREAT" title="Permalink to this definition">¶</a></dt>
918
 
<dt id="os.O_EXCL">
919
 
<code class="descclassname">os.</code><code class="descname">O_EXCL</code><a class="headerlink" href="#os.O_EXCL" title="Permalink to this definition">¶</a></dt>
920
 
<dt id="os.O_TRUNC">
921
 
<code class="descclassname">os.</code><code class="descname">O_TRUNC</code><a class="headerlink" href="#os.O_TRUNC" title="Permalink to this definition">¶</a></dt>
922
 
<dd><p>These constants are available on Unix and Windows.</p>
923
 
</dd></dl>
924
 
 
925
 
<dl class="data">
926
 
<dt id="os.O_DSYNC">
927
 
<code class="descclassname">os.</code><code class="descname">O_DSYNC</code><a class="headerlink" href="#os.O_DSYNC" title="Permalink to this definition">¶</a></dt>
928
 
<dt id="os.O_RSYNC">
929
 
<code class="descclassname">os.</code><code class="descname">O_RSYNC</code><a class="headerlink" href="#os.O_RSYNC" title="Permalink to this definition">¶</a></dt>
930
 
<dt id="os.O_SYNC">
931
 
<code class="descclassname">os.</code><code class="descname">O_SYNC</code><a class="headerlink" href="#os.O_SYNC" title="Permalink to this definition">¶</a></dt>
932
 
<dt id="os.O_NDELAY">
933
 
<code class="descclassname">os.</code><code class="descname">O_NDELAY</code><a class="headerlink" href="#os.O_NDELAY" title="Permalink to this definition">¶</a></dt>
934
 
<dt id="os.O_NONBLOCK">
935
 
<code class="descclassname">os.</code><code class="descname">O_NONBLOCK</code><a class="headerlink" href="#os.O_NONBLOCK" title="Permalink to this definition">¶</a></dt>
936
 
<dt id="os.O_NOCTTY">
937
 
<code class="descclassname">os.</code><code class="descname">O_NOCTTY</code><a class="headerlink" href="#os.O_NOCTTY" title="Permalink to this definition">¶</a></dt>
938
 
<dt id="os.O_SHLOCK">
939
 
<code class="descclassname">os.</code><code class="descname">O_SHLOCK</code><a class="headerlink" href="#os.O_SHLOCK" title="Permalink to this definition">¶</a></dt>
940
 
<dt id="os.O_EXLOCK">
941
 
<code class="descclassname">os.</code><code class="descname">O_EXLOCK</code><a class="headerlink" href="#os.O_EXLOCK" title="Permalink to this definition">¶</a></dt>
942
 
<dd><p>These constants are only available on Unix.</p>
943
 
</dd></dl>
944
 
 
945
 
<dl class="data">
946
 
<dt id="os.O_BINARY">
947
 
<code class="descclassname">os.</code><code class="descname">O_BINARY</code><a class="headerlink" href="#os.O_BINARY" title="Permalink to this definition">¶</a></dt>
948
 
<dt id="os.O_NOINHERIT">
949
 
<code class="descclassname">os.</code><code class="descname">O_NOINHERIT</code><a class="headerlink" href="#os.O_NOINHERIT" title="Permalink to this definition">¶</a></dt>
950
 
<dt id="os.O_SHORT_LIVED">
951
 
<code class="descclassname">os.</code><code class="descname">O_SHORT_LIVED</code><a class="headerlink" href="#os.O_SHORT_LIVED" title="Permalink to this definition">¶</a></dt>
952
 
<dt id="os.O_TEMPORARY">
953
 
<code class="descclassname">os.</code><code class="descname">O_TEMPORARY</code><a class="headerlink" href="#os.O_TEMPORARY" title="Permalink to this definition">¶</a></dt>
954
 
<dt id="os.O_RANDOM">
955
 
<code class="descclassname">os.</code><code class="descname">O_RANDOM</code><a class="headerlink" href="#os.O_RANDOM" title="Permalink to this definition">¶</a></dt>
956
 
<dt id="os.O_SEQUENTIAL">
957
 
<code class="descclassname">os.</code><code class="descname">O_SEQUENTIAL</code><a class="headerlink" href="#os.O_SEQUENTIAL" title="Permalink to this definition">¶</a></dt>
958
 
<dt id="os.O_TEXT">
959
 
<code class="descclassname">os.</code><code class="descname">O_TEXT</code><a class="headerlink" href="#os.O_TEXT" title="Permalink to this definition">¶</a></dt>
960
 
<dd><p>These constants are only available on Windows.</p>
961
 
</dd></dl>
962
 
 
963
 
<dl class="data">
964
 
<dt id="os.O_ASYNC">
965
 
<code class="descclassname">os.</code><code class="descname">O_ASYNC</code><a class="headerlink" href="#os.O_ASYNC" title="Permalink to this definition">¶</a></dt>
966
 
<dt id="os.O_DIRECT">
967
 
<code class="descclassname">os.</code><code class="descname">O_DIRECT</code><a class="headerlink" href="#os.O_DIRECT" title="Permalink to this definition">¶</a></dt>
968
 
<dt id="os.O_DIRECTORY">
969
 
<code class="descclassname">os.</code><code class="descname">O_DIRECTORY</code><a class="headerlink" href="#os.O_DIRECTORY" title="Permalink to this definition">¶</a></dt>
970
 
<dt id="os.O_NOFOLLOW">
971
 
<code class="descclassname">os.</code><code class="descname">O_NOFOLLOW</code><a class="headerlink" href="#os.O_NOFOLLOW" title="Permalink to this definition">¶</a></dt>
972
 
<dt id="os.O_NOATIME">
973
 
<code class="descclassname">os.</code><code class="descname">O_NOATIME</code><a class="headerlink" href="#os.O_NOATIME" title="Permalink to this definition">¶</a></dt>
974
 
<dd><p>These constants are GNU extensions and not present if they are not defined by
975
 
the C library.</p>
976
 
</dd></dl>
977
 
 
978
 
</div>
979
 
</div>
980
 
<div class="section" id="files-and-directories">
981
 
<span id="os-file-dir"></span><h2>15.1.4. Files and Directories<a class="headerlink" href="#files-and-directories" title="Permalink to this headline">¶</a></h2>
982
 
<dl class="function">
983
 
<dt id="os.access">
984
 
<code class="descclassname">os.</code><code class="descname">access</code><span class="sig-paren">(</span><em>path</em>, <em>mode</em><span class="sig-paren">)</span><a class="headerlink" href="#os.access" title="Permalink to this definition">¶</a></dt>
985
 
<dd><p>Use the real uid/gid to test for access to <em>path</em>.  Note that most operations
986
 
will use the effective uid/gid, therefore this routine can be used in a
987
 
suid/sgid environment to test if the invoking user has the specified access to
988
 
<em>path</em>.  <em>mode</em> should be <a class="reference internal" href="#os.F_OK" title="os.F_OK"><code class="xref py py-const docutils literal"><span class="pre">F_OK</span></code></a> to test the existence of <em>path</em>, or it
989
 
can be the inclusive OR of one or more of <a class="reference internal" href="#os.R_OK" title="os.R_OK"><code class="xref py py-const docutils literal"><span class="pre">R_OK</span></code></a>, <a class="reference internal" href="#os.W_OK" title="os.W_OK"><code class="xref py py-const docutils literal"><span class="pre">W_OK</span></code></a>, and
990
 
<a class="reference internal" href="#os.X_OK" title="os.X_OK"><code class="xref py py-const docutils literal"><span class="pre">X_OK</span></code></a> to test permissions.  Return <a class="reference internal" href="constants.html#True" title="True"><code class="xref py py-const docutils literal"><span class="pre">True</span></code></a> if access is allowed,
991
 
<a class="reference internal" href="constants.html#False" title="False"><code class="xref py py-const docutils literal"><span class="pre">False</span></code></a> if not. See the Unix man page <em class="manpage">access(2)</em> for more
992
 
information.</p>
993
 
<p>Availability: Unix, Windows.</p>
994
 
<div class="admonition note">
995
 
<p class="first admonition-title">Note</p>
996
 
<p>Using <a class="reference internal" href="#os.access" title="os.access"><code class="xref py py-func docutils literal"><span class="pre">access()</span></code></a> to check if a user is authorized to e.g. open a file
997
 
before actually doing so using <a class="reference internal" href="functions.html#open" title="open"><code class="xref py py-func docutils literal"><span class="pre">open()</span></code></a> creates a security hole,
998
 
because the user might exploit the short time interval between checking
999
 
and opening the file to manipulate it. It&#8217;s preferable to use <a class="reference internal" href="../glossary.html#term-eafp"><span class="xref std std-term">EAFP</span></a>
1000
 
techniques. For example:</p>
1001
 
<div class="highlight-python"><div class="highlight"><pre><span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">access</span><span class="p">(</span><span class="s2">&quot;myfile&quot;</span><span class="p">,</span> <span class="n">os</span><span class="o">.</span><span class="n">R_OK</span><span class="p">):</span>
1002
 
    <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="s2">&quot;myfile&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">fp</span><span class="p">:</span>
1003
 
        <span class="k">return</span> <span class="n">fp</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
1004
 
<span class="k">return</span> <span class="s2">&quot;some default data&quot;</span>
1005
 
</pre></div>
1006
 
</div>
1007
 
<p>is better written as:</p>
1008
 
<div class="last highlight-python"><div class="highlight"><pre><span class="k">try</span><span class="p">:</span>
1009
 
    <span class="n">fp</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="s2">&quot;myfile&quot;</span><span class="p">)</span>
1010
 
<span class="k">except</span> <span class="ne">IOError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
1011
 
    <span class="k">if</span> <span class="n">e</span><span class="o">.</span><span class="n">errno</span> <span class="o">==</span> <span class="n">errno</span><span class="o">.</span><span class="n">EACCES</span><span class="p">:</span>
1012
 
        <span class="k">return</span> <span class="s2">&quot;some default data&quot;</span>
1013
 
    <span class="c1"># Not a permission error.</span>
1014
 
    <span class="k">raise</span>
1015
 
<span class="k">else</span><span class="p">:</span>
1016
 
    <span class="k">with</span> <span class="n">fp</span><span class="p">:</span>
1017
 
        <span class="k">return</span> <span class="n">fp</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
1018
 
</pre></div>
1019
 
</div>
1020
 
</div>
1021
 
<div class="admonition note">
1022
 
<p class="first admonition-title">Note</p>
1023
 
<p class="last">I/O operations may fail even when <a class="reference internal" href="#os.access" title="os.access"><code class="xref py py-func docutils literal"><span class="pre">access()</span></code></a> indicates that they would
1024
 
succeed, particularly for operations on network filesystems which may have
1025
 
permissions semantics beyond the usual POSIX permission-bit model.</p>
1026
 
</div>
1027
 
</dd></dl>
1028
 
 
1029
 
<dl class="data">
1030
 
<dt id="os.F_OK">
1031
 
<code class="descclassname">os.</code><code class="descname">F_OK</code><a class="headerlink" href="#os.F_OK" title="Permalink to this definition">¶</a></dt>
1032
 
<dd><p>Value to pass as the <em>mode</em> parameter of <a class="reference internal" href="#os.access" title="os.access"><code class="xref py py-func docutils literal"><span class="pre">access()</span></code></a> to test the existence of
1033
 
<em>path</em>.</p>
1034
 
</dd></dl>
1035
 
 
1036
 
<dl class="data">
1037
 
<dt id="os.R_OK">
1038
 
<code class="descclassname">os.</code><code class="descname">R_OK</code><a class="headerlink" href="#os.R_OK" title="Permalink to this definition">¶</a></dt>
1039
 
<dd><p>Value to include in the <em>mode</em> parameter of <a class="reference internal" href="#os.access" title="os.access"><code class="xref py py-func docutils literal"><span class="pre">access()</span></code></a> to test the
1040
 
readability of <em>path</em>.</p>
1041
 
</dd></dl>
1042
 
 
1043
 
<dl class="data">
1044
 
<dt id="os.W_OK">
1045
 
<code class="descclassname">os.</code><code class="descname">W_OK</code><a class="headerlink" href="#os.W_OK" title="Permalink to this definition">¶</a></dt>
1046
 
<dd><p>Value to include in the <em>mode</em> parameter of <a class="reference internal" href="#os.access" title="os.access"><code class="xref py py-func docutils literal"><span class="pre">access()</span></code></a> to test the
1047
 
writability of <em>path</em>.</p>
1048
 
</dd></dl>
1049
 
 
1050
 
<dl class="data">
1051
 
<dt id="os.X_OK">
1052
 
<code class="descclassname">os.</code><code class="descname">X_OK</code><a class="headerlink" href="#os.X_OK" title="Permalink to this definition">¶</a></dt>
1053
 
<dd><p>Value to include in the <em>mode</em> parameter of <a class="reference internal" href="#os.access" title="os.access"><code class="xref py py-func docutils literal"><span class="pre">access()</span></code></a> to determine if
1054
 
<em>path</em> can be executed.</p>
1055
 
</dd></dl>
1056
 
 
1057
 
<dl class="function">
1058
 
<dt id="os.chdir">
1059
 
<code class="descclassname">os.</code><code class="descname">chdir</code><span class="sig-paren">(</span><em>path</em><span class="sig-paren">)</span><a class="headerlink" href="#os.chdir" title="Permalink to this definition">¶</a></dt>
1060
 
<dd><p id="index-13">Change the current working directory to <em>path</em>.</p>
1061
 
<p>Availability: Unix, Windows.</p>
1062
 
</dd></dl>
1063
 
 
1064
 
<dl class="function">
1065
 
<dt id="os.fchdir">
1066
 
<code class="descclassname">os.</code><code class="descname">fchdir</code><span class="sig-paren">(</span><em>fd</em><span class="sig-paren">)</span><a class="headerlink" href="#os.fchdir" title="Permalink to this definition">¶</a></dt>
1067
 
<dd><p>Change the current working directory to the directory represented by the file
1068
 
descriptor <em>fd</em>.  The descriptor must refer to an opened directory, not an open
1069
 
file.</p>
1070
 
<p>Availability: Unix.</p>
1071
 
<div class="versionadded">
1072
 
<p><span class="versionmodified">New in version 2.3.</span></p>
1073
 
</div>
1074
 
</dd></dl>
1075
 
 
1076
 
<dl class="function">
1077
 
<dt id="os.getcwd">
1078
 
<code class="descclassname">os.</code><code class="descname">getcwd</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.getcwd" title="Permalink to this definition">¶</a></dt>
1079
 
<dd><p>Return a string representing the current working directory.</p>
1080
 
<p>Availability: Unix, Windows.</p>
1081
 
</dd></dl>
1082
 
 
1083
 
<dl class="function">
1084
 
<dt id="os.getcwdu">
1085
 
<code class="descclassname">os.</code><code class="descname">getcwdu</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.getcwdu" title="Permalink to this definition">¶</a></dt>
1086
 
<dd><p>Return a Unicode object representing the current working directory.</p>
1087
 
<p>Availability: Unix, Windows.</p>
1088
 
<div class="versionadded">
1089
 
<p><span class="versionmodified">New in version 2.3.</span></p>
1090
 
</div>
1091
 
</dd></dl>
1092
 
 
1093
 
<dl class="function">
1094
 
<dt id="os.chflags">
1095
 
<code class="descclassname">os.</code><code class="descname">chflags</code><span class="sig-paren">(</span><em>path</em>, <em>flags</em><span class="sig-paren">)</span><a class="headerlink" href="#os.chflags" title="Permalink to this definition">¶</a></dt>
1096
 
<dd><p>Set the flags of <em>path</em> to the numeric <em>flags</em>. <em>flags</em> may take a combination
1097
 
(bitwise OR) of the following values (as defined in the <a class="reference internal" href="stat.html#module-stat" title="stat: Utilities for interpreting the results of os.stat(), os.lstat() and os.fstat()."><code class="xref py py-mod docutils literal"><span class="pre">stat</span></code></a> module):</p>
1098
 
<ul class="simple">
1099
 
<li><a class="reference internal" href="stat.html#stat.UF_NODUMP" title="stat.UF_NODUMP"><code class="xref py py-data docutils literal"><span class="pre">stat.UF_NODUMP</span></code></a></li>
1100
 
<li><a class="reference internal" href="stat.html#stat.UF_IMMUTABLE" title="stat.UF_IMMUTABLE"><code class="xref py py-data docutils literal"><span class="pre">stat.UF_IMMUTABLE</span></code></a></li>
1101
 
<li><a class="reference internal" href="stat.html#stat.UF_APPEND" title="stat.UF_APPEND"><code class="xref py py-data docutils literal"><span class="pre">stat.UF_APPEND</span></code></a></li>
1102
 
<li><a class="reference internal" href="stat.html#stat.UF_OPAQUE" title="stat.UF_OPAQUE"><code class="xref py py-data docutils literal"><span class="pre">stat.UF_OPAQUE</span></code></a></li>
1103
 
<li><a class="reference internal" href="stat.html#stat.UF_NOUNLINK" title="stat.UF_NOUNLINK"><code class="xref py py-data docutils literal"><span class="pre">stat.UF_NOUNLINK</span></code></a></li>
1104
 
<li><a class="reference internal" href="stat.html#stat.UF_COMPRESSED" title="stat.UF_COMPRESSED"><code class="xref py py-data docutils literal"><span class="pre">stat.UF_COMPRESSED</span></code></a></li>
1105
 
<li><a class="reference internal" href="stat.html#stat.UF_HIDDEN" title="stat.UF_HIDDEN"><code class="xref py py-data docutils literal"><span class="pre">stat.UF_HIDDEN</span></code></a></li>
1106
 
<li><a class="reference internal" href="stat.html#stat.SF_ARCHIVED" title="stat.SF_ARCHIVED"><code class="xref py py-data docutils literal"><span class="pre">stat.SF_ARCHIVED</span></code></a></li>
1107
 
<li><a class="reference internal" href="stat.html#stat.SF_IMMUTABLE" title="stat.SF_IMMUTABLE"><code class="xref py py-data docutils literal"><span class="pre">stat.SF_IMMUTABLE</span></code></a></li>
1108
 
<li><a class="reference internal" href="stat.html#stat.SF_APPEND" title="stat.SF_APPEND"><code class="xref py py-data docutils literal"><span class="pre">stat.SF_APPEND</span></code></a></li>
1109
 
<li><a class="reference internal" href="stat.html#stat.SF_NOUNLINK" title="stat.SF_NOUNLINK"><code class="xref py py-data docutils literal"><span class="pre">stat.SF_NOUNLINK</span></code></a></li>
1110
 
<li><a class="reference internal" href="stat.html#stat.SF_SNAPSHOT" title="stat.SF_SNAPSHOT"><code class="xref py py-data docutils literal"><span class="pre">stat.SF_SNAPSHOT</span></code></a></li>
1111
 
</ul>
1112
 
<p>Availability: Unix.</p>
1113
 
<div class="versionadded">
1114
 
<p><span class="versionmodified">New in version 2.6.</span></p>
1115
 
</div>
1116
 
</dd></dl>
1117
 
 
1118
 
<dl class="function">
1119
 
<dt id="os.chroot">
1120
 
<code class="descclassname">os.</code><code class="descname">chroot</code><span class="sig-paren">(</span><em>path</em><span class="sig-paren">)</span><a class="headerlink" href="#os.chroot" title="Permalink to this definition">¶</a></dt>
1121
 
<dd><p>Change the root directory of the current process to <em>path</em>. Availability:
1122
 
Unix.</p>
1123
 
<div class="versionadded">
1124
 
<p><span class="versionmodified">New in version 2.2.</span></p>
1125
 
</div>
1126
 
</dd></dl>
1127
 
 
1128
 
<dl class="function">
1129
 
<dt id="os.chmod">
1130
 
<code class="descclassname">os.</code><code class="descname">chmod</code><span class="sig-paren">(</span><em>path</em>, <em>mode</em><span class="sig-paren">)</span><a class="headerlink" href="#os.chmod" title="Permalink to this definition">¶</a></dt>
1131
 
<dd><p>Change the mode of <em>path</em> to the numeric <em>mode</em>. <em>mode</em> may take one of the
1132
 
following values (as defined in the <a class="reference internal" href="stat.html#module-stat" title="stat: Utilities for interpreting the results of os.stat(), os.lstat() and os.fstat()."><code class="xref py py-mod docutils literal"><span class="pre">stat</span></code></a> module) or bitwise ORed
1133
 
combinations of them:</p>
1134
 
<ul class="simple">
1135
 
<li><a class="reference internal" href="stat.html#stat.S_ISUID" title="stat.S_ISUID"><code class="xref py py-data docutils literal"><span class="pre">stat.S_ISUID</span></code></a></li>
1136
 
<li><a class="reference internal" href="stat.html#stat.S_ISGID" title="stat.S_ISGID"><code class="xref py py-data docutils literal"><span class="pre">stat.S_ISGID</span></code></a></li>
1137
 
<li><a class="reference internal" href="stat.html#stat.S_ENFMT" title="stat.S_ENFMT"><code class="xref py py-data docutils literal"><span class="pre">stat.S_ENFMT</span></code></a></li>
1138
 
<li><a class="reference internal" href="stat.html#stat.S_ISVTX" title="stat.S_ISVTX"><code class="xref py py-data docutils literal"><span class="pre">stat.S_ISVTX</span></code></a></li>
1139
 
<li><a class="reference internal" href="stat.html#stat.S_IREAD" title="stat.S_IREAD"><code class="xref py py-data docutils literal"><span class="pre">stat.S_IREAD</span></code></a></li>
1140
 
<li><a class="reference internal" href="stat.html#stat.S_IWRITE" title="stat.S_IWRITE"><code class="xref py py-data docutils literal"><span class="pre">stat.S_IWRITE</span></code></a></li>
1141
 
<li><a class="reference internal" href="stat.html#stat.S_IEXEC" title="stat.S_IEXEC"><code class="xref py py-data docutils literal"><span class="pre">stat.S_IEXEC</span></code></a></li>
1142
 
<li><a class="reference internal" href="stat.html#stat.S_IRWXU" title="stat.S_IRWXU"><code class="xref py py-data docutils literal"><span class="pre">stat.S_IRWXU</span></code></a></li>
1143
 
<li><a class="reference internal" href="stat.html#stat.S_IRUSR" title="stat.S_IRUSR"><code class="xref py py-data docutils literal"><span class="pre">stat.S_IRUSR</span></code></a></li>
1144
 
<li><a class="reference internal" href="stat.html#stat.S_IWUSR" title="stat.S_IWUSR"><code class="xref py py-data docutils literal"><span class="pre">stat.S_IWUSR</span></code></a></li>
1145
 
<li><a class="reference internal" href="stat.html#stat.S_IXUSR" title="stat.S_IXUSR"><code class="xref py py-data docutils literal"><span class="pre">stat.S_IXUSR</span></code></a></li>
1146
 
<li><a class="reference internal" href="stat.html#stat.S_IRWXG" title="stat.S_IRWXG"><code class="xref py py-data docutils literal"><span class="pre">stat.S_IRWXG</span></code></a></li>
1147
 
<li><a class="reference internal" href="stat.html#stat.S_IRGRP" title="stat.S_IRGRP"><code class="xref py py-data docutils literal"><span class="pre">stat.S_IRGRP</span></code></a></li>
1148
 
<li><a class="reference internal" href="stat.html#stat.S_IWGRP" title="stat.S_IWGRP"><code class="xref py py-data docutils literal"><span class="pre">stat.S_IWGRP</span></code></a></li>
1149
 
<li><a class="reference internal" href="stat.html#stat.S_IXGRP" title="stat.S_IXGRP"><code class="xref py py-data docutils literal"><span class="pre">stat.S_IXGRP</span></code></a></li>
1150
 
<li><a class="reference internal" href="stat.html#stat.S_IRWXO" title="stat.S_IRWXO"><code class="xref py py-data docutils literal"><span class="pre">stat.S_IRWXO</span></code></a></li>
1151
 
<li><a class="reference internal" href="stat.html#stat.S_IROTH" title="stat.S_IROTH"><code class="xref py py-data docutils literal"><span class="pre">stat.S_IROTH</span></code></a></li>
1152
 
<li><a class="reference internal" href="stat.html#stat.S_IWOTH" title="stat.S_IWOTH"><code class="xref py py-data docutils literal"><span class="pre">stat.S_IWOTH</span></code></a></li>
1153
 
<li><a class="reference internal" href="stat.html#stat.S_IXOTH" title="stat.S_IXOTH"><code class="xref py py-data docutils literal"><span class="pre">stat.S_IXOTH</span></code></a></li>
1154
 
</ul>
1155
 
<p>Availability: Unix, Windows.</p>
1156
 
<div class="admonition note">
1157
 
<p class="first admonition-title">Note</p>
1158
 
<p class="last">Although Windows supports <a class="reference internal" href="#os.chmod" title="os.chmod"><code class="xref py py-func docutils literal"><span class="pre">chmod()</span></code></a>, you can only  set the file&#8217;s read-only
1159
 
flag with it (via the <code class="docutils literal"><span class="pre">stat.S_IWRITE</span></code>  and <code class="docutils literal"><span class="pre">stat.S_IREAD</span></code>
1160
 
constants or a corresponding integer value).  All other bits are
1161
 
ignored.</p>
1162
 
</div>
1163
 
</dd></dl>
1164
 
 
1165
 
<dl class="function">
1166
 
<dt id="os.chown">
1167
 
<code class="descclassname">os.</code><code class="descname">chown</code><span class="sig-paren">(</span><em>path</em>, <em>uid</em>, <em>gid</em><span class="sig-paren">)</span><a class="headerlink" href="#os.chown" title="Permalink to this definition">¶</a></dt>
1168
 
<dd><p>Change the owner and group id of <em>path</em> to the numeric <em>uid</em> and <em>gid</em>. To leave
1169
 
one of the ids unchanged, set it to -1.</p>
1170
 
<p>Availability: Unix.</p>
1171
 
</dd></dl>
1172
 
 
1173
 
<dl class="function">
1174
 
<dt id="os.lchflags">
1175
 
<code class="descclassname">os.</code><code class="descname">lchflags</code><span class="sig-paren">(</span><em>path</em>, <em>flags</em><span class="sig-paren">)</span><a class="headerlink" href="#os.lchflags" title="Permalink to this definition">¶</a></dt>
1176
 
<dd><p>Set the flags of <em>path</em> to the numeric <em>flags</em>, like <a class="reference internal" href="#os.chflags" title="os.chflags"><code class="xref py py-func docutils literal"><span class="pre">chflags()</span></code></a>, but do not
1177
 
follow symbolic links.</p>
1178
 
<p>Availability: Unix.</p>
1179
 
<div class="versionadded">
1180
 
<p><span class="versionmodified">New in version 2.6.</span></p>
1181
 
</div>
1182
 
</dd></dl>
1183
 
 
1184
 
<dl class="function">
1185
 
<dt id="os.lchmod">
1186
 
<code class="descclassname">os.</code><code class="descname">lchmod</code><span class="sig-paren">(</span><em>path</em>, <em>mode</em><span class="sig-paren">)</span><a class="headerlink" href="#os.lchmod" title="Permalink to this definition">¶</a></dt>
1187
 
<dd><p>Change the mode of <em>path</em> to the numeric <em>mode</em>. If path is a symlink, this
1188
 
affects the symlink rather than the target. See the docs for <a class="reference internal" href="#os.chmod" title="os.chmod"><code class="xref py py-func docutils literal"><span class="pre">chmod()</span></code></a>
1189
 
for possible values of <em>mode</em>.</p>
1190
 
<p>Availability: Unix.</p>
1191
 
<div class="versionadded">
1192
 
<p><span class="versionmodified">New in version 2.6.</span></p>
1193
 
</div>
1194
 
</dd></dl>
1195
 
 
1196
 
<dl class="function">
1197
 
<dt id="os.lchown">
1198
 
<code class="descclassname">os.</code><code class="descname">lchown</code><span class="sig-paren">(</span><em>path</em>, <em>uid</em>, <em>gid</em><span class="sig-paren">)</span><a class="headerlink" href="#os.lchown" title="Permalink to this definition">¶</a></dt>
1199
 
<dd><p>Change the owner and group id of <em>path</em> to the numeric <em>uid</em> and <em>gid</em>. This
1200
 
function will not follow symbolic links.</p>
1201
 
<p>Availability: Unix.</p>
1202
 
<div class="versionadded">
1203
 
<p><span class="versionmodified">New in version 2.3.</span></p>
1204
 
</div>
1205
 
</dd></dl>
1206
 
 
1207
 
<dl class="function">
1208
 
<dt id="os.link">
1209
 
<code class="descclassname">os.</code><code class="descname">link</code><span class="sig-paren">(</span><em>source</em>, <em>link_name</em><span class="sig-paren">)</span><a class="headerlink" href="#os.link" title="Permalink to this definition">¶</a></dt>
1210
 
<dd><p>Create a hard link pointing to <em>source</em> named <em>link_name</em>.</p>
1211
 
<p>Availability: Unix.</p>
1212
 
</dd></dl>
1213
 
 
1214
 
<dl class="function">
1215
 
<dt id="os.listdir">
1216
 
<code class="descclassname">os.</code><code class="descname">listdir</code><span class="sig-paren">(</span><em>path</em><span class="sig-paren">)</span><a class="headerlink" href="#os.listdir" title="Permalink to this definition">¶</a></dt>
1217
 
<dd><p>Return a list containing the names of the entries in the directory given by
1218
 
<em>path</em>.  The list is in arbitrary order.  It does not include the special
1219
 
entries <code class="docutils literal"><span class="pre">'.'</span></code> and <code class="docutils literal"><span class="pre">'..'</span></code> even if they are present in the
1220
 
directory.</p>
1221
 
<p>Availability: Unix, Windows.</p>
1222
 
<div class="versionchanged">
1223
 
<p><span class="versionmodified">Changed in version 2.3: </span>On Windows NT/2k/XP and Unix, if <em>path</em> is a Unicode object, the result will be
1224
 
a list of Unicode objects. Undecodable filenames will still be returned as
1225
 
string objects.</p>
1226
 
</div>
1227
 
</dd></dl>
1228
 
 
1229
 
<dl class="function">
1230
 
<dt id="os.lstat">
1231
 
<code class="descclassname">os.</code><code class="descname">lstat</code><span class="sig-paren">(</span><em>path</em><span class="sig-paren">)</span><a class="headerlink" href="#os.lstat" title="Permalink to this definition">¶</a></dt>
1232
 
<dd><p>Perform the equivalent of an <code class="xref c c-func docutils literal"><span class="pre">lstat()</span></code> system call on the given path.
1233
 
Similar to <a class="reference internal" href="#os.stat" title="os.stat"><code class="xref py py-func docutils literal"><span class="pre">stat()</span></code></a>, but does not follow symbolic links.  On
1234
 
platforms that do not support symbolic links, this is an alias for
1235
 
<a class="reference internal" href="#os.stat" title="os.stat"><code class="xref py py-func docutils literal"><span class="pre">stat()</span></code></a>.</p>
1236
 
</dd></dl>
1237
 
 
1238
 
<dl class="function">
1239
 
<dt id="os.mkfifo">
1240
 
<code class="descclassname">os.</code><code class="descname">mkfifo</code><span class="sig-paren">(</span><em>path</em><span class="optional">[</span>, <em>mode</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#os.mkfifo" title="Permalink to this definition">¶</a></dt>
1241
 
<dd><p>Create a FIFO (a named pipe) named <em>path</em> with numeric mode <em>mode</em>.  The default
1242
 
<em>mode</em> is <code class="docutils literal"><span class="pre">0666</span></code> (octal).  The current umask value is first masked out from
1243
 
the mode.</p>
1244
 
<p>Availability: Unix.</p>
1245
 
<p>FIFOs are pipes that can be accessed like regular files.  FIFOs exist until they
1246
 
are deleted (for example with <a class="reference internal" href="#os.unlink" title="os.unlink"><code class="xref py py-func docutils literal"><span class="pre">os.unlink()</span></code></a>). Generally, FIFOs are used as
1247
 
rendezvous between &#8220;client&#8221; and &#8220;server&#8221; type processes: the server opens the
1248
 
FIFO for reading, and the client opens it for writing.  Note that <a class="reference internal" href="#os.mkfifo" title="os.mkfifo"><code class="xref py py-func docutils literal"><span class="pre">mkfifo()</span></code></a>
1249
 
doesn&#8217;t open the FIFO &#8212; it just creates the rendezvous point.</p>
1250
 
</dd></dl>
1251
 
 
1252
 
<dl class="function">
1253
 
<dt id="os.mknod">
1254
 
<code class="descclassname">os.</code><code class="descname">mknod</code><span class="sig-paren">(</span><em>filename</em><span class="optional">[</span>, <em>mode=0600</em><span class="optional">[</span>, <em>device=0</em><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#os.mknod" title="Permalink to this definition">¶</a></dt>
1255
 
<dd><p>Create a filesystem node (file, device special file or named pipe) named
1256
 
<em>filename</em>. <em>mode</em> specifies both the permissions to use and the type of node to
1257
 
be created, being combined (bitwise OR) with one of <code class="docutils literal"><span class="pre">stat.S_IFREG</span></code>,
1258
 
<code class="docutils literal"><span class="pre">stat.S_IFCHR</span></code>, <code class="docutils literal"><span class="pre">stat.S_IFBLK</span></code>,
1259
 
and <code class="docutils literal"><span class="pre">stat.S_IFIFO</span></code> (those constants are available in <a class="reference internal" href="stat.html#module-stat" title="stat: Utilities for interpreting the results of os.stat(), os.lstat() and os.fstat()."><code class="xref py py-mod docutils literal"><span class="pre">stat</span></code></a>).
1260
 
For <code class="docutils literal"><span class="pre">stat.S_IFCHR</span></code> and
1261
 
<code class="docutils literal"><span class="pre">stat.S_IFBLK</span></code>, <em>device</em> defines the newly created device special file (probably using
1262
 
<a class="reference internal" href="#os.makedev" title="os.makedev"><code class="xref py py-func docutils literal"><span class="pre">os.makedev()</span></code></a>), otherwise it is ignored.</p>
1263
 
<div class="versionadded">
1264
 
<p><span class="versionmodified">New in version 2.3.</span></p>
1265
 
</div>
1266
 
</dd></dl>
1267
 
 
1268
 
<dl class="function">
1269
 
<dt id="os.major">
1270
 
<code class="descclassname">os.</code><code class="descname">major</code><span class="sig-paren">(</span><em>device</em><span class="sig-paren">)</span><a class="headerlink" href="#os.major" title="Permalink to this definition">¶</a></dt>
1271
 
<dd><p>Extract the device major number from a raw device number (usually the
1272
 
<code class="xref py py-attr docutils literal"><span class="pre">st_dev</span></code> or <code class="xref py py-attr docutils literal"><span class="pre">st_rdev</span></code> field from <code class="xref c c-type docutils literal"><span class="pre">stat</span></code>).</p>
1273
 
<div class="versionadded">
1274
 
<p><span class="versionmodified">New in version 2.3.</span></p>
1275
 
</div>
1276
 
</dd></dl>
1277
 
 
1278
 
<dl class="function">
1279
 
<dt id="os.minor">
1280
 
<code class="descclassname">os.</code><code class="descname">minor</code><span class="sig-paren">(</span><em>device</em><span class="sig-paren">)</span><a class="headerlink" href="#os.minor" title="Permalink to this definition">¶</a></dt>
1281
 
<dd><p>Extract the device minor number from a raw device number (usually the
1282
 
<code class="xref py py-attr docutils literal"><span class="pre">st_dev</span></code> or <code class="xref py py-attr docutils literal"><span class="pre">st_rdev</span></code> field from <code class="xref c c-type docutils literal"><span class="pre">stat</span></code>).</p>
1283
 
<div class="versionadded">
1284
 
<p><span class="versionmodified">New in version 2.3.</span></p>
1285
 
</div>
1286
 
</dd></dl>
1287
 
 
1288
 
<dl class="function">
1289
 
<dt id="os.makedev">
1290
 
<code class="descclassname">os.</code><code class="descname">makedev</code><span class="sig-paren">(</span><em>major</em>, <em>minor</em><span class="sig-paren">)</span><a class="headerlink" href="#os.makedev" title="Permalink to this definition">¶</a></dt>
1291
 
<dd><p>Compose a raw device number from the major and minor device numbers.</p>
1292
 
<div class="versionadded">
1293
 
<p><span class="versionmodified">New in version 2.3.</span></p>
1294
 
</div>
1295
 
</dd></dl>
1296
 
 
1297
 
<dl class="function">
1298
 
<dt id="os.mkdir">
1299
 
<code class="descclassname">os.</code><code class="descname">mkdir</code><span class="sig-paren">(</span><em>path</em><span class="optional">[</span>, <em>mode</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#os.mkdir" title="Permalink to this definition">¶</a></dt>
1300
 
<dd><p>Create a directory named <em>path</em> with numeric mode <em>mode</em>. The default <em>mode</em> is
1301
 
<code class="docutils literal"><span class="pre">0777</span></code> (octal).  On some systems, <em>mode</em> is ignored.  Where it is used, the
1302
 
current umask value is first masked out.  If the directory already exists,
1303
 
<a class="reference internal" href="exceptions.html#exceptions.OSError" title="exceptions.OSError"><code class="xref py py-exc docutils literal"><span class="pre">OSError</span></code></a> is raised.</p>
1304
 
<p>It is also possible to create temporary directories; see the
1305
 
<a class="reference internal" href="tempfile.html#module-tempfile" title="tempfile: Generate temporary files and directories."><code class="xref py py-mod docutils literal"><span class="pre">tempfile</span></code></a> module&#8217;s <a class="reference internal" href="tempfile.html#tempfile.mkdtemp" title="tempfile.mkdtemp"><code class="xref py py-func docutils literal"><span class="pre">tempfile.mkdtemp()</span></code></a> function.</p>
1306
 
<p>Availability: Unix, Windows.</p>
1307
 
</dd></dl>
1308
 
 
1309
 
<dl class="function">
1310
 
<dt id="os.makedirs">
1311
 
<code class="descclassname">os.</code><code class="descname">makedirs</code><span class="sig-paren">(</span><em>path</em><span class="optional">[</span>, <em>mode</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#os.makedirs" title="Permalink to this definition">¶</a></dt>
1312
 
<dd><p id="index-14">Recursive directory creation function.  Like <a class="reference internal" href="#os.mkdir" title="os.mkdir"><code class="xref py py-func docutils literal"><span class="pre">mkdir()</span></code></a>, but makes all
1313
 
intermediate-level directories needed to contain the leaf directory.  Raises an
1314
 
<a class="reference internal" href="#os.error" title="os.error"><code class="xref py py-exc docutils literal"><span class="pre">error</span></code></a> exception if the leaf directory already exists or cannot be
1315
 
created.  The default <em>mode</em> is <code class="docutils literal"><span class="pre">0777</span></code> (octal).  On some systems, <em>mode</em> is
1316
 
ignored. Where it is used, the current umask value is first masked out.</p>
1317
 
<div class="admonition note">
1318
 
<p class="first admonition-title">Note</p>
1319
 
<p class="last"><a class="reference internal" href="#os.makedirs" title="os.makedirs"><code class="xref py py-func docutils literal"><span class="pre">makedirs()</span></code></a> will become confused if the path elements to create include
1320
 
<a class="reference internal" href="#os.pardir" title="os.pardir"><code class="xref py py-data docutils literal"><span class="pre">os.pardir</span></code></a>.</p>
1321
 
</div>
1322
 
<div class="versionadded">
1323
 
<p><span class="versionmodified">New in version 1.5.2.</span></p>
1324
 
</div>
1325
 
<div class="versionchanged">
1326
 
<p><span class="versionmodified">Changed in version 2.3: </span>This function now handles UNC paths correctly.</p>
1327
 
</div>
1328
 
</dd></dl>
1329
 
 
1330
 
<dl class="function">
1331
 
<dt id="os.pathconf">
1332
 
<code class="descclassname">os.</code><code class="descname">pathconf</code><span class="sig-paren">(</span><em>path</em>, <em>name</em><span class="sig-paren">)</span><a class="headerlink" href="#os.pathconf" title="Permalink to this definition">¶</a></dt>
1333
 
<dd><p>Return system configuration information relevant to a named file. <em>name</em>
1334
 
specifies the configuration value to retrieve; it may be a string which is the
1335
 
name of a defined system value; these names are specified in a number of
1336
 
standards (POSIX.1, Unix 95, Unix 98, and others).  Some platforms define
1337
 
additional names as well.  The names known to the host operating system are
1338
 
given in the <code class="docutils literal"><span class="pre">pathconf_names</span></code> dictionary.  For configuration variables not
1339
 
included in that mapping, passing an integer for <em>name</em> is also accepted.</p>
1340
 
<p>If <em>name</em> is a string and is not known, <a class="reference internal" href="exceptions.html#exceptions.ValueError" title="exceptions.ValueError"><code class="xref py py-exc docutils literal"><span class="pre">ValueError</span></code></a> is raised.  If a
1341
 
specific value for <em>name</em> is not supported by the host system, even if it is
1342
 
included in <code class="docutils literal"><span class="pre">pathconf_names</span></code>, an <a class="reference internal" href="exceptions.html#exceptions.OSError" title="exceptions.OSError"><code class="xref py py-exc docutils literal"><span class="pre">OSError</span></code></a> is raised with
1343
 
<a class="reference internal" href="errno.html#errno.EINVAL" title="errno.EINVAL"><code class="xref py py-const docutils literal"><span class="pre">errno.EINVAL</span></code></a> for the error number.</p>
1344
 
<p>Availability: Unix.</p>
1345
 
</dd></dl>
1346
 
 
1347
 
<dl class="data">
1348
 
<dt id="os.pathconf_names">
1349
 
<code class="descclassname">os.</code><code class="descname">pathconf_names</code><a class="headerlink" href="#os.pathconf_names" title="Permalink to this definition">¶</a></dt>
1350
 
<dd><p>Dictionary mapping names accepted by <a class="reference internal" href="#os.pathconf" title="os.pathconf"><code class="xref py py-func docutils literal"><span class="pre">pathconf()</span></code></a> and <a class="reference internal" href="#os.fpathconf" title="os.fpathconf"><code class="xref py py-func docutils literal"><span class="pre">fpathconf()</span></code></a> to
1351
 
the integer values defined for those names by the host operating system.  This
1352
 
can be used to determine the set of names known to the system. Availability:
1353
 
Unix.</p>
1354
 
</dd></dl>
1355
 
 
1356
 
<dl class="function">
1357
 
<dt id="os.readlink">
1358
 
<code class="descclassname">os.</code><code class="descname">readlink</code><span class="sig-paren">(</span><em>path</em><span class="sig-paren">)</span><a class="headerlink" href="#os.readlink" title="Permalink to this definition">¶</a></dt>
1359
 
<dd><p>Return a string representing the path to which the symbolic link points.  The
1360
 
result may be either an absolute or relative pathname; if it is relative, it may
1361
 
be converted to an absolute pathname using <code class="docutils literal"><span class="pre">os.path.join(os.path.dirname(path),</span>
1362
 
<span class="pre">result)</span></code>.</p>
1363
 
<div class="versionchanged">
1364
 
<p><span class="versionmodified">Changed in version 2.6: </span>If the <em>path</em> is a Unicode object the result will also be a Unicode object.</p>
1365
 
</div>
1366
 
<p>Availability: Unix.</p>
1367
 
</dd></dl>
1368
 
 
1369
 
<dl class="function">
1370
 
<dt id="os.remove">
1371
 
<code class="descclassname">os.</code><code class="descname">remove</code><span class="sig-paren">(</span><em>path</em><span class="sig-paren">)</span><a class="headerlink" href="#os.remove" title="Permalink to this definition">¶</a></dt>
1372
 
<dd><p>Remove (delete) the file <em>path</em>.  If <em>path</em> is a directory, <a class="reference internal" href="exceptions.html#exceptions.OSError" title="exceptions.OSError"><code class="xref py py-exc docutils literal"><span class="pre">OSError</span></code></a> is
1373
 
raised; see <a class="reference internal" href="#os.rmdir" title="os.rmdir"><code class="xref py py-func docutils literal"><span class="pre">rmdir()</span></code></a> below to remove a directory.  This is identical to
1374
 
the <a class="reference internal" href="#os.unlink" title="os.unlink"><code class="xref py py-func docutils literal"><span class="pre">unlink()</span></code></a> function documented below.  On Windows, attempting to
1375
 
remove a file that is in use causes an exception to be raised; on Unix, the
1376
 
directory entry is removed but the storage allocated to the file is not made
1377
 
available until the original file is no longer in use.</p>
1378
 
<p>Availability: Unix, Windows.</p>
1379
 
</dd></dl>
1380
 
 
1381
 
<dl class="function">
1382
 
<dt id="os.removedirs">
1383
 
<code class="descclassname">os.</code><code class="descname">removedirs</code><span class="sig-paren">(</span><em>path</em><span class="sig-paren">)</span><a class="headerlink" href="#os.removedirs" title="Permalink to this definition">¶</a></dt>
1384
 
<dd><p id="index-15">Remove directories recursively.  Works like <a class="reference internal" href="#os.rmdir" title="os.rmdir"><code class="xref py py-func docutils literal"><span class="pre">rmdir()</span></code></a> except that, if the
1385
 
leaf directory is successfully removed, <a class="reference internal" href="#os.removedirs" title="os.removedirs"><code class="xref py py-func docutils literal"><span class="pre">removedirs()</span></code></a>  tries to
1386
 
successively remove every parent directory mentioned in  <em>path</em> until an error
1387
 
is raised (which is ignored, because it generally means that a parent directory
1388
 
is not empty). For example, <code class="docutils literal"><span class="pre">os.removedirs('foo/bar/baz')</span></code> will first remove
1389
 
the directory <code class="docutils literal"><span class="pre">'foo/bar/baz'</span></code>, and then remove <code class="docutils literal"><span class="pre">'foo/bar'</span></code> and <code class="docutils literal"><span class="pre">'foo'</span></code> if
1390
 
they are empty. Raises <a class="reference internal" href="exceptions.html#exceptions.OSError" title="exceptions.OSError"><code class="xref py py-exc docutils literal"><span class="pre">OSError</span></code></a> if the leaf directory could not be
1391
 
successfully removed.</p>
1392
 
<div class="versionadded">
1393
 
<p><span class="versionmodified">New in version 1.5.2.</span></p>
1394
 
</div>
1395
 
</dd></dl>
1396
 
 
1397
 
<dl class="function">
1398
 
<dt id="os.rename">
1399
 
<code class="descclassname">os.</code><code class="descname">rename</code><span class="sig-paren">(</span><em>src</em>, <em>dst</em><span class="sig-paren">)</span><a class="headerlink" href="#os.rename" title="Permalink to this definition">¶</a></dt>
1400
 
<dd><p>Rename the file or directory <em>src</em> to <em>dst</em>.  If <em>dst</em> is a directory,
1401
 
<a class="reference internal" href="exceptions.html#exceptions.OSError" title="exceptions.OSError"><code class="xref py py-exc docutils literal"><span class="pre">OSError</span></code></a> will be raised.  On Unix, if <em>dst</em> exists and is a file, it will
1402
 
be replaced silently if the user has permission.  The operation may fail on some
1403
 
Unix flavors if <em>src</em> and <em>dst</em> are on different filesystems.  If successful,
1404
 
the renaming will be an atomic operation (this is a POSIX requirement).  On
1405
 
Windows, if <em>dst</em> already exists, <a class="reference internal" href="exceptions.html#exceptions.OSError" title="exceptions.OSError"><code class="xref py py-exc docutils literal"><span class="pre">OSError</span></code></a> will be raised even if it is a
1406
 
file; there may be no way to implement an atomic rename when <em>dst</em> names an
1407
 
existing file.</p>
1408
 
<p>Availability: Unix, Windows.</p>
1409
 
</dd></dl>
1410
 
 
1411
 
<dl class="function">
1412
 
<dt id="os.renames">
1413
 
<code class="descclassname">os.</code><code class="descname">renames</code><span class="sig-paren">(</span><em>old</em>, <em>new</em><span class="sig-paren">)</span><a class="headerlink" href="#os.renames" title="Permalink to this definition">¶</a></dt>
1414
 
<dd><p>Recursive directory or file renaming function. Works like <a class="reference internal" href="#os.rename" title="os.rename"><code class="xref py py-func docutils literal"><span class="pre">rename()</span></code></a>, except
1415
 
creation of any intermediate directories needed to make the new pathname good is
1416
 
attempted first. After the rename, directories corresponding to rightmost path
1417
 
segments of the old name will be pruned away using <a class="reference internal" href="#os.removedirs" title="os.removedirs"><code class="xref py py-func docutils literal"><span class="pre">removedirs()</span></code></a>.</p>
1418
 
<div class="versionadded">
1419
 
<p><span class="versionmodified">New in version 1.5.2.</span></p>
1420
 
</div>
1421
 
<div class="admonition note">
1422
 
<p class="first admonition-title">Note</p>
1423
 
<p class="last">This function can fail with the new directory structure made if you lack
1424
 
permissions needed to remove the leaf directory or file.</p>
1425
 
</div>
1426
 
</dd></dl>
1427
 
 
1428
 
<dl class="function">
1429
 
<dt id="os.rmdir">
1430
 
<code class="descclassname">os.</code><code class="descname">rmdir</code><span class="sig-paren">(</span><em>path</em><span class="sig-paren">)</span><a class="headerlink" href="#os.rmdir" title="Permalink to this definition">¶</a></dt>
1431
 
<dd><p>Remove (delete) the directory <em>path</em>.  Only works when the directory is
1432
 
empty, otherwise, <a class="reference internal" href="exceptions.html#exceptions.OSError" title="exceptions.OSError"><code class="xref py py-exc docutils literal"><span class="pre">OSError</span></code></a> is raised.  In order to remove whole
1433
 
directory trees, <a class="reference internal" href="shutil.html#shutil.rmtree" title="shutil.rmtree"><code class="xref py py-func docutils literal"><span class="pre">shutil.rmtree()</span></code></a> can be used.</p>
1434
 
<p>Availability: Unix, Windows.</p>
1435
 
</dd></dl>
1436
 
 
1437
 
<dl class="function">
1438
 
<dt id="os.stat">
1439
 
<code class="descclassname">os.</code><code class="descname">stat</code><span class="sig-paren">(</span><em>path</em><span class="sig-paren">)</span><a class="headerlink" href="#os.stat" title="Permalink to this definition">¶</a></dt>
1440
 
<dd><p>Perform the equivalent of a <code class="xref c c-func docutils literal"><span class="pre">stat()</span></code> system call on the given path.
1441
 
(This function follows symlinks; to stat a symlink use <a class="reference internal" href="#os.lstat" title="os.lstat"><code class="xref py py-func docutils literal"><span class="pre">lstat()</span></code></a>.)</p>
1442
 
<p>The return value is an object whose attributes correspond to the members
1443
 
of the <code class="xref c c-type docutils literal"><span class="pre">stat</span></code> structure, namely:</p>
1444
 
<ul class="simple">
1445
 
<li><code class="xref py py-attr docutils literal"><span class="pre">st_mode</span></code> - protection bits,</li>
1446
 
<li><code class="xref py py-attr docutils literal"><span class="pre">st_ino</span></code> - inode number,</li>
1447
 
<li><code class="xref py py-attr docutils literal"><span class="pre">st_dev</span></code> - device,</li>
1448
 
<li><code class="xref py py-attr docutils literal"><span class="pre">st_nlink</span></code> - number of hard links,</li>
1449
 
<li><code class="xref py py-attr docutils literal"><span class="pre">st_uid</span></code> - user id of owner,</li>
1450
 
<li><code class="xref py py-attr docutils literal"><span class="pre">st_gid</span></code> - group id of owner,</li>
1451
 
<li><code class="xref py py-attr docutils literal"><span class="pre">st_size</span></code> - size of file, in bytes,</li>
1452
 
<li><code class="xref py py-attr docutils literal"><span class="pre">st_atime</span></code> - time of most recent access,</li>
1453
 
<li><code class="xref py py-attr docutils literal"><span class="pre">st_mtime</span></code> - time of most recent content modification,</li>
1454
 
<li><code class="xref py py-attr docutils literal"><span class="pre">st_ctime</span></code> - platform dependent; time of most recent metadata change on
1455
 
Unix, or the time of creation on Windows)</li>
1456
 
</ul>
1457
 
<div class="versionchanged">
1458
 
<p><span class="versionmodified">Changed in version 2.3: </span>If <a class="reference internal" href="#os.stat_float_times" title="os.stat_float_times"><code class="xref py py-func docutils literal"><span class="pre">stat_float_times()</span></code></a> returns <code class="docutils literal"><span class="pre">True</span></code>, the time values are floats, measuring
1459
 
seconds. Fractions of a second may be reported if the system supports that.
1460
 
See <a class="reference internal" href="#os.stat_float_times" title="os.stat_float_times"><code class="xref py py-func docutils literal"><span class="pre">stat_float_times()</span></code></a> for further discussion.</p>
1461
 
</div>
1462
 
<p>On some Unix systems (such as Linux), the following attributes may also be
1463
 
available:</p>
1464
 
<ul class="simple">
1465
 
<li><code class="xref py py-attr docutils literal"><span class="pre">st_blocks</span></code> - number of 512-byte blocks allocated for file</li>
1466
 
<li><code class="xref py py-attr docutils literal"><span class="pre">st_blksize</span></code> - filesystem blocksize for efficient file system I/O</li>
1467
 
<li><code class="xref py py-attr docutils literal"><span class="pre">st_rdev</span></code> - type of device if an inode device</li>
1468
 
<li><code class="xref py py-attr docutils literal"><span class="pre">st_flags</span></code> - user defined flags for file</li>
1469
 
</ul>
1470
 
<p>On other Unix systems (such as FreeBSD), the following attributes may be
1471
 
available (but may be only filled out if root tries to use them):</p>
1472
 
<ul class="simple">
1473
 
<li><code class="xref py py-attr docutils literal"><span class="pre">st_gen</span></code> - file generation number</li>
1474
 
<li><code class="xref py py-attr docutils literal"><span class="pre">st_birthtime</span></code> - time of file creation</li>
1475
 
</ul>
1476
 
<p>On RISCOS systems, the following attributes are also available:</p>
1477
 
<ul class="simple">
1478
 
<li><code class="xref py py-attr docutils literal"><span class="pre">st_ftype</span></code> (file type)</li>
1479
 
<li><code class="xref py py-attr docutils literal"><span class="pre">st_attrs</span></code> (attributes)</li>
1480
 
<li><code class="xref py py-attr docutils literal"><span class="pre">st_obtype</span></code> (object type).</li>
1481
 
</ul>
1482
 
<div class="admonition note">
1483
 
<p class="first admonition-title">Note</p>
1484
 
<p class="last">The exact meaning and resolution of the <code class="xref py py-attr docutils literal"><span class="pre">st_atime</span></code>,
1485
 
<code class="xref py py-attr docutils literal"><span class="pre">st_mtime</span></code>, and <code class="xref py py-attr docutils literal"><span class="pre">st_ctime</span></code> attributes depend on the operating
1486
 
system and the file system. For example, on Windows systems using the FAT
1487
 
or FAT32 file systems, <code class="xref py py-attr docutils literal"><span class="pre">st_mtime</span></code> has 2-second resolution, and
1488
 
<code class="xref py py-attr docutils literal"><span class="pre">st_atime</span></code> has only 1-day resolution.  See your operating system
1489
 
documentation for details.</p>
1490
 
</div>
1491
 
<p>For backward compatibility, the return value of <a class="reference internal" href="#os.stat" title="os.stat"><code class="xref py py-func docutils literal"><span class="pre">stat()</span></code></a> is also accessible
1492
 
as a tuple of at least 10 integers giving the most important (and portable)
1493
 
members of the <code class="xref c c-type docutils literal"><span class="pre">stat</span></code> structure, in the order <code class="xref py py-attr docutils literal"><span class="pre">st_mode</span></code>,
1494
 
<code class="xref py py-attr docutils literal"><span class="pre">st_ino</span></code>, <code class="xref py py-attr docutils literal"><span class="pre">st_dev</span></code>, <code class="xref py py-attr docutils literal"><span class="pre">st_nlink</span></code>, <code class="xref py py-attr docutils literal"><span class="pre">st_uid</span></code>,
1495
 
<code class="xref py py-attr docutils literal"><span class="pre">st_gid</span></code>, <code class="xref py py-attr docutils literal"><span class="pre">st_size</span></code>, <code class="xref py py-attr docutils literal"><span class="pre">st_atime</span></code>, <code class="xref py py-attr docutils literal"><span class="pre">st_mtime</span></code>,
1496
 
<code class="xref py py-attr docutils literal"><span class="pre">st_ctime</span></code>. More items may be added at the end by some implementations.</p>
1497
 
<p id="index-16">The standard module <a class="reference internal" href="stat.html#module-stat" title="stat: Utilities for interpreting the results of os.stat(), os.lstat() and os.fstat()."><code class="xref py py-mod docutils literal"><span class="pre">stat</span></code></a> defines functions and constants that are useful
1498
 
for extracting information from a <code class="xref c c-type docutils literal"><span class="pre">stat</span></code> structure. (On Windows, some
1499
 
items are filled with dummy values.)</p>
1500
 
<p>Example:</p>
1501
 
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">os</span>
1502
 
<span class="gp">&gt;&gt;&gt; </span><span class="n">statinfo</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">stat</span><span class="p">(</span><span class="s1">&#39;somefile.txt&#39;</span><span class="p">)</span>
1503
 
<span class="gp">&gt;&gt;&gt; </span><span class="n">statinfo</span>
1504
 
<span class="go">(33188, 422511, 769, 1, 1032, 100, 926, 1105022698,1105022732, 1105022732)</span>
1505
 
<span class="gp">&gt;&gt;&gt; </span><span class="n">statinfo</span><span class="o">.</span><span class="n">st_size</span>
1506
 
<span class="go">926</span>
1507
 
</pre></div>
1508
 
</div>
1509
 
<p>Availability: Unix, Windows.</p>
1510
 
<div class="versionchanged">
1511
 
<p><span class="versionmodified">Changed in version 2.2: </span>Added access to values as attributes of the returned object.</p>
1512
 
</div>
1513
 
<div class="versionchanged">
1514
 
<p><span class="versionmodified">Changed in version 2.5: </span>Added <code class="xref py py-attr docutils literal"><span class="pre">st_gen</span></code> and <code class="xref py py-attr docutils literal"><span class="pre">st_birthtime</span></code>.</p>
1515
 
</div>
1516
 
</dd></dl>
1517
 
 
1518
 
<dl class="function">
1519
 
<dt id="os.stat_float_times">
1520
 
<code class="descclassname">os.</code><code class="descname">stat_float_times</code><span class="sig-paren">(</span><span class="optional">[</span><em>newvalue</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#os.stat_float_times" title="Permalink to this definition">¶</a></dt>
1521
 
<dd><p>Determine whether <code class="xref py py-class docutils literal"><span class="pre">stat_result</span></code> represents time stamps as float objects.
1522
 
If <em>newvalue</em> is <code class="docutils literal"><span class="pre">True</span></code>, future calls to <a class="reference internal" href="#os.stat" title="os.stat"><code class="xref py py-func docutils literal"><span class="pre">stat()</span></code></a> return floats, if it is
1523
 
<code class="docutils literal"><span class="pre">False</span></code>, future calls return ints. If <em>newvalue</em> is omitted, return the
1524
 
current setting.</p>
1525
 
<p>For compatibility with older Python versions, accessing <code class="xref py py-class docutils literal"><span class="pre">stat_result</span></code> as
1526
 
a tuple always returns integers.</p>
1527
 
<div class="versionchanged">
1528
 
<p><span class="versionmodified">Changed in version 2.5: </span>Python now returns float values by default. Applications which do not work
1529
 
correctly with floating point time stamps can use this function to restore the
1530
 
old behaviour.</p>
1531
 
</div>
1532
 
<p>The resolution of the timestamps (that is the smallest possible fraction)
1533
 
depends on the system. Some systems only support second resolution; on these
1534
 
systems, the fraction will always be zero.</p>
1535
 
<p>It is recommended that this setting is only changed at program startup time in
1536
 
the <em>__main__</em> module; libraries should never change this setting. If an
1537
 
application uses a library that works incorrectly if floating point time stamps
1538
 
are processed, this application should turn the feature off until the library
1539
 
has been corrected.</p>
1540
 
</dd></dl>
1541
 
 
1542
 
<dl class="function">
1543
 
<dt id="os.statvfs">
1544
 
<code class="descclassname">os.</code><code class="descname">statvfs</code><span class="sig-paren">(</span><em>path</em><span class="sig-paren">)</span><a class="headerlink" href="#os.statvfs" title="Permalink to this definition">¶</a></dt>
1545
 
<dd><p>Perform a <code class="xref c c-func docutils literal"><span class="pre">statvfs()</span></code> system call on the given path.  The return value is
1546
 
an object whose attributes describe the filesystem on the given path, and
1547
 
correspond to the members of the <code class="xref c c-type docutils literal"><span class="pre">statvfs</span></code> structure, namely:
1548
 
<code class="xref py py-attr docutils literal"><span class="pre">f_bsize</span></code>, <code class="xref py py-attr docutils literal"><span class="pre">f_frsize</span></code>, <code class="xref py py-attr docutils literal"><span class="pre">f_blocks</span></code>, <code class="xref py py-attr docutils literal"><span class="pre">f_bfree</span></code>,
1549
 
<code class="xref py py-attr docutils literal"><span class="pre">f_bavail</span></code>, <code class="xref py py-attr docutils literal"><span class="pre">f_files</span></code>, <code class="xref py py-attr docutils literal"><span class="pre">f_ffree</span></code>, <code class="xref py py-attr docutils literal"><span class="pre">f_favail</span></code>,
1550
 
<code class="xref py py-attr docutils literal"><span class="pre">f_flag</span></code>, <code class="xref py py-attr docutils literal"><span class="pre">f_namemax</span></code>.</p>
1551
 
<p id="index-17">For backward compatibility, the return value is also accessible as a tuple whose
1552
 
values correspond to the attributes, in the order given above. The standard
1553
 
module <a class="reference internal" href="statvfs.html#module-statvfs" title="statvfs: Constants for interpreting the result of os.statvfs(). (deprecated)"><code class="xref py py-mod docutils literal"><span class="pre">statvfs</span></code></a> defines constants that are useful for extracting
1554
 
information from a <code class="xref c c-type docutils literal"><span class="pre">statvfs</span></code> structure when accessing it as a sequence;
1555
 
this remains useful when writing code that needs to work with versions of Python
1556
 
that don&#8217;t support accessing the fields as attributes.</p>
1557
 
<p>Availability: Unix.</p>
1558
 
<div class="versionchanged">
1559
 
<p><span class="versionmodified">Changed in version 2.2: </span>Added access to values as attributes of the returned object.</p>
1560
 
</div>
1561
 
</dd></dl>
1562
 
 
1563
 
<dl class="function">
1564
 
<dt id="os.symlink">
1565
 
<code class="descclassname">os.</code><code class="descname">symlink</code><span class="sig-paren">(</span><em>source</em>, <em>link_name</em><span class="sig-paren">)</span><a class="headerlink" href="#os.symlink" title="Permalink to this definition">¶</a></dt>
1566
 
<dd><p>Create a symbolic link pointing to <em>source</em> named <em>link_name</em>.</p>
1567
 
<p>Availability: Unix.</p>
1568
 
</dd></dl>
1569
 
 
1570
 
<dl class="function">
1571
 
<dt id="os.tempnam">
1572
 
<code class="descclassname">os.</code><code class="descname">tempnam</code><span class="sig-paren">(</span><span class="optional">[</span><em>dir</em><span class="optional">[</span>, <em>prefix</em><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#os.tempnam" title="Permalink to this definition">¶</a></dt>
1573
 
<dd><p>Return a unique path name that is reasonable for creating a temporary file.
1574
 
This will be an absolute path that names a potential directory entry in the
1575
 
directory <em>dir</em> or a common location for temporary files if <em>dir</em> is omitted or
1576
 
<code class="docutils literal"><span class="pre">None</span></code>.  If given and not <code class="docutils literal"><span class="pre">None</span></code>, <em>prefix</em> is used to provide a short prefix
1577
 
to the filename.  Applications are responsible for properly creating and
1578
 
managing files created using paths returned by <a class="reference internal" href="#os.tempnam" title="os.tempnam"><code class="xref py py-func docutils literal"><span class="pre">tempnam()</span></code></a>; no automatic
1579
 
cleanup is provided. On Unix, the environment variable <span class="target" id="index-18"></span><code class="xref std std-envvar docutils literal"><span class="pre">TMPDIR</span></code>
1580
 
overrides <em>dir</em>, while on Windows <span class="target" id="index-19"></span><code class="xref std std-envvar docutils literal"><span class="pre">TMP</span></code> is used.  The specific
1581
 
behavior of this function depends on the C library implementation; some aspects
1582
 
are underspecified in system documentation.</p>
1583
 
<div class="admonition warning">
1584
 
<p class="first admonition-title">Warning</p>
1585
 
<p class="last">Use of <a class="reference internal" href="#os.tempnam" title="os.tempnam"><code class="xref py py-func docutils literal"><span class="pre">tempnam()</span></code></a> is vulnerable to symlink attacks; consider using
1586
 
<a class="reference internal" href="#os.tmpfile" title="os.tmpfile"><code class="xref py py-func docutils literal"><span class="pre">tmpfile()</span></code></a> (section <a class="reference internal" href="#os-newstreams"><span>File Object Creation</span></a>) instead.</p>
1587
 
</div>
1588
 
<p>Availability: Unix, Windows.</p>
1589
 
</dd></dl>
1590
 
 
1591
 
<dl class="function">
1592
 
<dt id="os.tmpnam">
1593
 
<code class="descclassname">os.</code><code class="descname">tmpnam</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.tmpnam" title="Permalink to this definition">¶</a></dt>
1594
 
<dd><p>Return a unique path name that is reasonable for creating a temporary file.
1595
 
This will be an absolute path that names a potential directory entry in a common
1596
 
location for temporary files.  Applications are responsible for properly
1597
 
creating and managing files created using paths returned by <a class="reference internal" href="#os.tmpnam" title="os.tmpnam"><code class="xref py py-func docutils literal"><span class="pre">tmpnam()</span></code></a>; no
1598
 
automatic cleanup is provided.</p>
1599
 
<div class="admonition warning">
1600
 
<p class="first admonition-title">Warning</p>
1601
 
<p class="last">Use of <a class="reference internal" href="#os.tmpnam" title="os.tmpnam"><code class="xref py py-func docutils literal"><span class="pre">tmpnam()</span></code></a> is vulnerable to symlink attacks; consider using
1602
 
<a class="reference internal" href="#os.tmpfile" title="os.tmpfile"><code class="xref py py-func docutils literal"><span class="pre">tmpfile()</span></code></a> (section <a class="reference internal" href="#os-newstreams"><span>File Object Creation</span></a>) instead.</p>
1603
 
</div>
1604
 
<p>Availability: Unix, Windows.  This function probably shouldn&#8217;t be used on
1605
 
Windows, though: Microsoft&#8217;s implementation of <a class="reference internal" href="#os.tmpnam" title="os.tmpnam"><code class="xref py py-func docutils literal"><span class="pre">tmpnam()</span></code></a> always creates a
1606
 
name in the root directory of the current drive, and that&#8217;s generally a poor
1607
 
location for a temp file (depending on privileges, you may not even be able to
1608
 
open a file using this name).</p>
1609
 
</dd></dl>
1610
 
 
1611
 
<dl class="data">
1612
 
<dt id="os.TMP_MAX">
1613
 
<code class="descclassname">os.</code><code class="descname">TMP_MAX</code><a class="headerlink" href="#os.TMP_MAX" title="Permalink to this definition">¶</a></dt>
1614
 
<dd><p>The maximum number of unique names that <a class="reference internal" href="#os.tmpnam" title="os.tmpnam"><code class="xref py py-func docutils literal"><span class="pre">tmpnam()</span></code></a> will generate before
1615
 
reusing names.</p>
1616
 
</dd></dl>
1617
 
 
1618
 
<dl class="function">
1619
 
<dt id="os.unlink">
1620
 
<code class="descclassname">os.</code><code class="descname">unlink</code><span class="sig-paren">(</span><em>path</em><span class="sig-paren">)</span><a class="headerlink" href="#os.unlink" title="Permalink to this definition">¶</a></dt>
1621
 
<dd><p>Remove (delete) the file <em>path</em>.  This is the same function as
1622
 
<a class="reference internal" href="#os.remove" title="os.remove"><code class="xref py py-func docutils literal"><span class="pre">remove()</span></code></a>; the <a class="reference internal" href="#os.unlink" title="os.unlink"><code class="xref py py-func docutils literal"><span class="pre">unlink()</span></code></a> name is its traditional Unix
1623
 
name.</p>
1624
 
<p>Availability: Unix, Windows.</p>
1625
 
</dd></dl>
1626
 
 
1627
 
<dl class="function">
1628
 
<dt id="os.utime">
1629
 
<code class="descclassname">os.</code><code class="descname">utime</code><span class="sig-paren">(</span><em>path</em>, <em>times</em><span class="sig-paren">)</span><a class="headerlink" href="#os.utime" title="Permalink to this definition">¶</a></dt>
1630
 
<dd><p>Set the access and modified times of the file specified by <em>path</em>. If <em>times</em>
1631
 
is <code class="docutils literal"><span class="pre">None</span></code>, then the file&#8217;s access and modified times are set to the current
1632
 
time. (The effect is similar to running the Unix program <strong class="program">touch</strong> on
1633
 
the path.)  Otherwise, <em>times</em> must be a 2-tuple of numbers, of the form
1634
 
<code class="docutils literal"><span class="pre">(atime,</span> <span class="pre">mtime)</span></code> which is used to set the access and modified times,
1635
 
respectively. Whether a directory can be given for <em>path</em> depends on whether
1636
 
the operating system implements directories as files (for example, Windows
1637
 
does not).  Note that the exact times you set here may not be returned by a
1638
 
subsequent <a class="reference internal" href="#os.stat" title="os.stat"><code class="xref py py-func docutils literal"><span class="pre">stat()</span></code></a> call, depending on the resolution with which your
1639
 
operating system records access and modification times; see <a class="reference internal" href="#os.stat" title="os.stat"><code class="xref py py-func docutils literal"><span class="pre">stat()</span></code></a>.</p>
1640
 
<div class="versionchanged">
1641
 
<p><span class="versionmodified">Changed in version 2.0: </span>Added support for <code class="docutils literal"><span class="pre">None</span></code> for <em>times</em>.</p>
1642
 
</div>
1643
 
<p>Availability: Unix, Windows.</p>
1644
 
</dd></dl>
1645
 
 
1646
 
<dl class="function">
1647
 
<dt id="os.walk">
1648
 
<code class="descclassname">os.</code><code class="descname">walk</code><span class="sig-paren">(</span><em>top</em>, <em>topdown=True</em>, <em>onerror=None</em>, <em>followlinks=False</em><span class="sig-paren">)</span><a class="headerlink" href="#os.walk" title="Permalink to this definition">¶</a></dt>
1649
 
<dd><p id="index-20">Generate the file names in a directory tree by walking the tree
1650
 
either top-down or bottom-up. For each directory in the tree rooted at directory
1651
 
<em>top</em> (including <em>top</em> itself), it yields a 3-tuple <code class="docutils literal"><span class="pre">(dirpath,</span> <span class="pre">dirnames,</span>
1652
 
<span class="pre">filenames)</span></code>.</p>
1653
 
<p><em>dirpath</em> is a string, the path to the directory.  <em>dirnames</em> is a list of the
1654
 
names of the subdirectories in <em>dirpath</em> (excluding <code class="docutils literal"><span class="pre">'.'</span></code> and <code class="docutils literal"><span class="pre">'..'</span></code>).
1655
 
<em>filenames</em> is a list of the names of the non-directory files in <em>dirpath</em>.
1656
 
Note that the names in the lists contain no path components.  To get a full path
1657
 
(which begins with <em>top</em>) to a file or directory in <em>dirpath</em>, do
1658
 
<code class="docutils literal"><span class="pre">os.path.join(dirpath,</span> <span class="pre">name)</span></code>.</p>
1659
 
<p>If optional argument <em>topdown</em> is <code class="docutils literal"><span class="pre">True</span></code> or not specified, the triple for a
1660
 
directory is generated before the triples for any of its subdirectories
1661
 
(directories are generated top-down).  If <em>topdown</em> is <code class="docutils literal"><span class="pre">False</span></code>, the triple
1662
 
for a directory is generated after the triples for all of its subdirectories
1663
 
(directories are generated bottom-up). No matter the value of <em>topdown</em>, the
1664
 
list of subdirectories is retrieved before the tuples for the directory and
1665
 
its subdirectories are generated.</p>
1666
 
<p>When <em>topdown</em> is <code class="docutils literal"><span class="pre">True</span></code>, the caller can modify the <em>dirnames</em> list in-place
1667
 
(perhaps using <a class="reference internal" href="../reference/simple_stmts.html#del"><code class="xref std std-keyword docutils literal"><span class="pre">del</span></code></a> or slice assignment), and <a class="reference internal" href="#os.walk" title="os.walk"><code class="xref py py-func docutils literal"><span class="pre">walk()</span></code></a> will only
1668
 
recurse into the subdirectories whose names remain in <em>dirnames</em>; this can be
1669
 
used to prune the search, impose a specific order of visiting, or even to inform
1670
 
<a class="reference internal" href="#os.walk" title="os.walk"><code class="xref py py-func docutils literal"><span class="pre">walk()</span></code></a> about directories the caller creates or renames before it resumes
1671
 
<a class="reference internal" href="#os.walk" title="os.walk"><code class="xref py py-func docutils literal"><span class="pre">walk()</span></code></a> again.  Modifying <em>dirnames</em> when <em>topdown</em> is <code class="docutils literal"><span class="pre">False</span></code> has
1672
 
no effect on the behavior of the walk, because in bottom-up mode the directories
1673
 
in <em>dirnames</em> are generated before <em>dirpath</em> itself is generated.</p>
1674
 
<p>By default, errors from the <a class="reference internal" href="#os.listdir" title="os.listdir"><code class="xref py py-func docutils literal"><span class="pre">listdir()</span></code></a> call are ignored.  If optional
1675
 
argument <em>onerror</em> is specified, it should be a function; it will be called with
1676
 
one argument, an <a class="reference internal" href="exceptions.html#exceptions.OSError" title="exceptions.OSError"><code class="xref py py-exc docutils literal"><span class="pre">OSError</span></code></a> instance.  It can report the error to continue
1677
 
with the walk, or raise the exception to abort the walk.  Note that the filename
1678
 
is available as the <code class="docutils literal"><span class="pre">filename</span></code> attribute of the exception object.</p>
1679
 
<p>By default, <a class="reference internal" href="#os.walk" title="os.walk"><code class="xref py py-func docutils literal"><span class="pre">walk()</span></code></a> will not walk down into symbolic links that resolve to
1680
 
directories. Set <em>followlinks</em> to <code class="docutils literal"><span class="pre">True</span></code> to visit directories pointed to by
1681
 
symlinks, on systems that support them.</p>
1682
 
<div class="versionadded">
1683
 
<p><span class="versionmodified">New in version 2.6: </span>The <em>followlinks</em> parameter.</p>
1684
 
</div>
1685
 
<div class="admonition note">
1686
 
<p class="first admonition-title">Note</p>
1687
 
<p class="last">Be aware that setting <em>followlinks</em> to <code class="docutils literal"><span class="pre">True</span></code> can lead to infinite recursion if a
1688
 
link points to a parent directory of itself. <a class="reference internal" href="#os.walk" title="os.walk"><code class="xref py py-func docutils literal"><span class="pre">walk()</span></code></a> does not keep track of
1689
 
the directories it visited already.</p>
1690
 
</div>
1691
 
<div class="admonition note">
1692
 
<p class="first admonition-title">Note</p>
1693
 
<p class="last">If you pass a relative pathname, don&#8217;t change the current working directory
1694
 
between resumptions of <a class="reference internal" href="#os.walk" title="os.walk"><code class="xref py py-func docutils literal"><span class="pre">walk()</span></code></a>.  <a class="reference internal" href="#os.walk" title="os.walk"><code class="xref py py-func docutils literal"><span class="pre">walk()</span></code></a> never changes the current
1695
 
directory, and assumes that its caller doesn&#8217;t either.</p>
1696
 
</div>
1697
 
<p>This example displays the number of bytes taken by non-directory files in each
1698
 
directory under the starting directory, except that it doesn&#8217;t look under any
1699
 
CVS subdirectory:</p>
1700
 
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">os</span>
1701
 
<span class="kn">from</span> <span class="nn">os.path</span> <span class="kn">import</span> <span class="n">join</span><span class="p">,</span> <span class="n">getsize</span>
1702
 
<span class="k">for</span> <span class="n">root</span><span class="p">,</span> <span class="n">dirs</span><span class="p">,</span> <span class="n">files</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">walk</span><span class="p">(</span><span class="s1">&#39;python/Lib/email&#39;</span><span class="p">):</span>
1703
 
    <span class="k">print</span> <span class="n">root</span><span class="p">,</span> <span class="s2">&quot;consumes&quot;</span><span class="p">,</span>
1704
 
    <span class="k">print</span> <span class="nb">sum</span><span class="p">(</span><span class="n">getsize</span><span class="p">(</span><span class="n">join</span><span class="p">(</span><span class="n">root</span><span class="p">,</span> <span class="n">name</span><span class="p">))</span> <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">files</span><span class="p">),</span>
1705
 
    <span class="k">print</span> <span class="s2">&quot;bytes in&quot;</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">files</span><span class="p">),</span> <span class="s2">&quot;non-directory files&quot;</span>
1706
 
    <span class="k">if</span> <span class="s1">&#39;CVS&#39;</span> <span class="ow">in</span> <span class="n">dirs</span><span class="p">:</span>
1707
 
        <span class="n">dirs</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="s1">&#39;CVS&#39;</span><span class="p">)</span>  <span class="c1"># don&#39;t visit CVS directories</span>
1708
 
</pre></div>
1709
 
</div>
1710
 
<p>In the next example, walking the tree bottom-up is essential: <a class="reference internal" href="#os.rmdir" title="os.rmdir"><code class="xref py py-func docutils literal"><span class="pre">rmdir()</span></code></a>
1711
 
doesn&#8217;t allow deleting a directory before the directory is empty:</p>
1712
 
<div class="highlight-python"><div class="highlight"><pre><span class="c1"># Delete everything reachable from the directory named in &quot;top&quot;,</span>
1713
 
<span class="c1"># assuming there are no symbolic links.</span>
1714
 
<span class="c1"># CAUTION:  This is dangerous!  For example, if top == &#39;/&#39;, it</span>
1715
 
<span class="c1"># could delete all your disk files.</span>
1716
 
<span class="kn">import</span> <span class="nn">os</span>
1717
 
<span class="k">for</span> <span class="n">root</span><span class="p">,</span> <span class="n">dirs</span><span class="p">,</span> <span class="n">files</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">walk</span><span class="p">(</span><span class="n">top</span><span class="p">,</span> <span class="n">topdown</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
1718
 
    <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">files</span><span class="p">:</span>
1719
 
        <span class="n">os</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">root</span><span class="p">,</span> <span class="n">name</span><span class="p">))</span>
1720
 
    <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">dirs</span><span class="p">:</span>
1721
 
        <span class="n">os</span><span class="o">.</span><span class="n">rmdir</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">root</span><span class="p">,</span> <span class="n">name</span><span class="p">))</span>
1722
 
</pre></div>
1723
 
</div>
1724
 
<div class="versionadded">
1725
 
<p><span class="versionmodified">New in version 2.3.</span></p>
1726
 
</div>
1727
 
</dd></dl>
1728
 
 
1729
 
</div>
1730
 
<div class="section" id="process-management">
1731
 
<span id="os-process"></span><h2>15.1.5. Process Management<a class="headerlink" href="#process-management" title="Permalink to this headline">¶</a></h2>
1732
 
<p>These functions may be used to create and manage processes.</p>
1733
 
<p>The various <a class="reference internal" href="#os.execl" title="os.execl"><code class="xref py py-func docutils literal"><span class="pre">exec*</span></code></a> functions take a list of arguments for the new
1734
 
program loaded into the process.  In each case, the first of these arguments is
1735
 
passed to the new program as its own name rather than as an argument a user may
1736
 
have typed on a command line.  For the C programmer, this is the <code class="docutils literal"><span class="pre">argv[0]</span></code>
1737
 
passed to a program&#8217;s <code class="xref c c-func docutils literal"><span class="pre">main()</span></code>.  For example, <code class="docutils literal"><span class="pre">os.execv('/bin/echo',</span>
1738
 
<span class="pre">['foo',</span> <span class="pre">'bar'])</span></code> will only print <code class="docutils literal"><span class="pre">bar</span></code> on standard output; <code class="docutils literal"><span class="pre">foo</span></code> will seem
1739
 
to be ignored.</p>
1740
 
<dl class="function">
1741
 
<dt id="os.abort">
1742
 
<code class="descclassname">os.</code><code class="descname">abort</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.abort" title="Permalink to this definition">¶</a></dt>
1743
 
<dd><p>Generate a <code class="xref py py-const docutils literal"><span class="pre">SIGABRT</span></code> signal to the current process.  On Unix, the default
1744
 
behavior is to produce a core dump; on Windows, the process immediately returns
1745
 
an exit code of <code class="docutils literal"><span class="pre">3</span></code>.  Be aware that calling this function will not call the
1746
 
Python signal handler registered for <code class="xref py py-const docutils literal"><span class="pre">SIGABRT</span></code> with
1747
 
<a class="reference internal" href="signal.html#signal.signal" title="signal.signal"><code class="xref py py-func docutils literal"><span class="pre">signal.signal()</span></code></a>.</p>
1748
 
<p>Availability: Unix, Windows.</p>
1749
 
</dd></dl>
1750
 
 
1751
 
<dl class="function">
1752
 
<dt id="os.execl">
1753
 
<code class="descclassname">os.</code><code class="descname">execl</code><span class="sig-paren">(</span><em>path</em>, <em>arg0</em>, <em>arg1</em>, <em>...</em><span class="sig-paren">)</span><a class="headerlink" href="#os.execl" title="Permalink to this definition">¶</a></dt>
1754
 
<dt id="os.execle">
1755
 
<code class="descclassname">os.</code><code class="descname">execle</code><span class="sig-paren">(</span><em>path</em>, <em>arg0</em>, <em>arg1</em>, <em>...</em>, <em>env</em><span class="sig-paren">)</span><a class="headerlink" href="#os.execle" title="Permalink to this definition">¶</a></dt>
1756
 
<dt id="os.execlp">
1757
 
<code class="descclassname">os.</code><code class="descname">execlp</code><span class="sig-paren">(</span><em>file</em>, <em>arg0</em>, <em>arg1</em>, <em>...</em><span class="sig-paren">)</span><a class="headerlink" href="#os.execlp" title="Permalink to this definition">¶</a></dt>
1758
 
<dt id="os.execlpe">
1759
 
<code class="descclassname">os.</code><code class="descname">execlpe</code><span class="sig-paren">(</span><em>file</em>, <em>arg0</em>, <em>arg1</em>, <em>...</em>, <em>env</em><span class="sig-paren">)</span><a class="headerlink" href="#os.execlpe" title="Permalink to this definition">¶</a></dt>
1760
 
<dt id="os.execv">
1761
 
<code class="descclassname">os.</code><code class="descname">execv</code><span class="sig-paren">(</span><em>path</em>, <em>args</em><span class="sig-paren">)</span><a class="headerlink" href="#os.execv" title="Permalink to this definition">¶</a></dt>
1762
 
<dt id="os.execve">
1763
 
<code class="descclassname">os.</code><code class="descname">execve</code><span class="sig-paren">(</span><em>path</em>, <em>args</em>, <em>env</em><span class="sig-paren">)</span><a class="headerlink" href="#os.execve" title="Permalink to this definition">¶</a></dt>
1764
 
<dt id="os.execvp">
1765
 
<code class="descclassname">os.</code><code class="descname">execvp</code><span class="sig-paren">(</span><em>file</em>, <em>args</em><span class="sig-paren">)</span><a class="headerlink" href="#os.execvp" title="Permalink to this definition">¶</a></dt>
1766
 
<dt id="os.execvpe">
1767
 
<code class="descclassname">os.</code><code class="descname">execvpe</code><span class="sig-paren">(</span><em>file</em>, <em>args</em>, <em>env</em><span class="sig-paren">)</span><a class="headerlink" href="#os.execvpe" title="Permalink to this definition">¶</a></dt>
1768
 
<dd><p>These functions all execute a new program, replacing the current process; they
1769
 
do not return.  On Unix, the new executable is loaded into the current process,
1770
 
and will have the same process id as the caller.  Errors will be reported as
1771
 
<a class="reference internal" href="exceptions.html#exceptions.OSError" title="exceptions.OSError"><code class="xref py py-exc docutils literal"><span class="pre">OSError</span></code></a> exceptions.</p>
1772
 
<p>The current process is replaced immediately. Open file objects and
1773
 
descriptors are not flushed, so if there may be data buffered
1774
 
on these open files, you should flush them using
1775
 
<code class="xref py py-func docutils literal"><span class="pre">sys.stdout.flush()</span></code> or <a class="reference internal" href="#os.fsync" title="os.fsync"><code class="xref py py-func docutils literal"><span class="pre">os.fsync()</span></code></a> before calling an
1776
 
<a class="reference internal" href="#os.execl" title="os.execl"><code class="xref py py-func docutils literal"><span class="pre">exec*</span></code></a> function.</p>
1777
 
<p>The &#8220;l&#8221; and &#8220;v&#8221; variants of the <a class="reference internal" href="#os.execl" title="os.execl"><code class="xref py py-func docutils literal"><span class="pre">exec*</span></code></a> functions differ in how
1778
 
command-line arguments are passed.  The &#8220;l&#8221; variants are perhaps the easiest
1779
 
to work with if the number of parameters is fixed when the code is written; the
1780
 
individual parameters simply become additional parameters to the <code class="xref py py-func docutils literal"><span class="pre">execl*()</span></code>
1781
 
functions.  The &#8220;v&#8221; variants are good when the number of parameters is
1782
 
variable, with the arguments being passed in a list or tuple as the <em>args</em>
1783
 
parameter.  In either case, the arguments to the child process should start with
1784
 
the name of the command being run, but this is not enforced.</p>
1785
 
<p>The variants which include a &#8220;p&#8221; near the end (<a class="reference internal" href="#os.execlp" title="os.execlp"><code class="xref py py-func docutils literal"><span class="pre">execlp()</span></code></a>,
1786
 
<a class="reference internal" href="#os.execlpe" title="os.execlpe"><code class="xref py py-func docutils literal"><span class="pre">execlpe()</span></code></a>, <a class="reference internal" href="#os.execvp" title="os.execvp"><code class="xref py py-func docutils literal"><span class="pre">execvp()</span></code></a>, and <a class="reference internal" href="#os.execvpe" title="os.execvpe"><code class="xref py py-func docutils literal"><span class="pre">execvpe()</span></code></a>) will use the
1787
 
<span class="target" id="index-21"></span><code class="xref std std-envvar docutils literal"><span class="pre">PATH</span></code> environment variable to locate the program <em>file</em>.  When the
1788
 
environment is being replaced (using one of the <a class="reference internal" href="#os.execl" title="os.execl"><code class="xref py py-func docutils literal"><span class="pre">exec*e</span></code></a> variants,
1789
 
discussed in the next paragraph), the new environment is used as the source of
1790
 
the <span class="target" id="index-22"></span><code class="xref std std-envvar docutils literal"><span class="pre">PATH</span></code> variable. The other variants, <a class="reference internal" href="#os.execl" title="os.execl"><code class="xref py py-func docutils literal"><span class="pre">execl()</span></code></a>, <a class="reference internal" href="#os.execle" title="os.execle"><code class="xref py py-func docutils literal"><span class="pre">execle()</span></code></a>,
1791
 
<a class="reference internal" href="#os.execv" title="os.execv"><code class="xref py py-func docutils literal"><span class="pre">execv()</span></code></a>, and <a class="reference internal" href="#os.execve" title="os.execve"><code class="xref py py-func docutils literal"><span class="pre">execve()</span></code></a>, will not use the <span class="target" id="index-23"></span><code class="xref std std-envvar docutils literal"><span class="pre">PATH</span></code> variable to
1792
 
locate the executable; <em>path</em> must contain an appropriate absolute or relative
1793
 
path.</p>
1794
 
<p>For <a class="reference internal" href="#os.execle" title="os.execle"><code class="xref py py-func docutils literal"><span class="pre">execle()</span></code></a>, <a class="reference internal" href="#os.execlpe" title="os.execlpe"><code class="xref py py-func docutils literal"><span class="pre">execlpe()</span></code></a>, <a class="reference internal" href="#os.execve" title="os.execve"><code class="xref py py-func docutils literal"><span class="pre">execve()</span></code></a>, and <a class="reference internal" href="#os.execvpe" title="os.execvpe"><code class="xref py py-func docutils literal"><span class="pre">execvpe()</span></code></a> (note
1795
 
that these all end in &#8220;e&#8221;), the <em>env</em> parameter must be a mapping which is
1796
 
used to define the environment variables for the new process (these are used
1797
 
instead of the current process&#8217; environment); the functions <a class="reference internal" href="#os.execl" title="os.execl"><code class="xref py py-func docutils literal"><span class="pre">execl()</span></code></a>,
1798
 
<a class="reference internal" href="#os.execlp" title="os.execlp"><code class="xref py py-func docutils literal"><span class="pre">execlp()</span></code></a>, <a class="reference internal" href="#os.execv" title="os.execv"><code class="xref py py-func docutils literal"><span class="pre">execv()</span></code></a>, and <a class="reference internal" href="#os.execvp" title="os.execvp"><code class="xref py py-func docutils literal"><span class="pre">execvp()</span></code></a> all cause the new process to
1799
 
inherit the environment of the current process.</p>
1800
 
<p>Availability: Unix, Windows.</p>
1801
 
</dd></dl>
1802
 
 
1803
 
<dl class="function">
1804
 
<dt id="os._exit">
1805
 
<code class="descclassname">os.</code><code class="descname">_exit</code><span class="sig-paren">(</span><em>n</em><span class="sig-paren">)</span><a class="headerlink" href="#os._exit" title="Permalink to this definition">¶</a></dt>
1806
 
<dd><p>Exit the process with status <em>n</em>, without calling cleanup handlers, flushing
1807
 
stdio buffers, etc.</p>
1808
 
<p>Availability: Unix, Windows.</p>
1809
 
<div class="admonition note">
1810
 
<p class="first admonition-title">Note</p>
1811
 
<p class="last">The standard way to exit is <code class="docutils literal"><span class="pre">sys.exit(n)</span></code>.  <a class="reference internal" href="#os._exit" title="os._exit"><code class="xref py py-func docutils literal"><span class="pre">_exit()</span></code></a> should
1812
 
normally only be used in the child process after a <a class="reference internal" href="#os.fork" title="os.fork"><code class="xref py py-func docutils literal"><span class="pre">fork()</span></code></a>.</p>
1813
 
</div>
1814
 
</dd></dl>
1815
 
 
1816
 
<p>The following exit codes are defined and can be used with <a class="reference internal" href="#os._exit" title="os._exit"><code class="xref py py-func docutils literal"><span class="pre">_exit()</span></code></a>,
1817
 
although they are not required.  These are typically used for system programs
1818
 
written in Python, such as a mail server&#8217;s external command delivery program.</p>
1819
 
<div class="admonition note">
1820
 
<p class="first admonition-title">Note</p>
1821
 
<p class="last">Some of these may not be available on all Unix platforms, since there is some
1822
 
variation.  These constants are defined where they are defined by the underlying
1823
 
platform.</p>
1824
 
</div>
1825
 
<dl class="data">
1826
 
<dt id="os.EX_OK">
1827
 
<code class="descclassname">os.</code><code class="descname">EX_OK</code><a class="headerlink" href="#os.EX_OK" title="Permalink to this definition">¶</a></dt>
1828
 
<dd><p>Exit code that means no error occurred.</p>
1829
 
<p>Availability: Unix.</p>
1830
 
<div class="versionadded">
1831
 
<p><span class="versionmodified">New in version 2.3.</span></p>
1832
 
</div>
1833
 
</dd></dl>
1834
 
 
1835
 
<dl class="data">
1836
 
<dt id="os.EX_USAGE">
1837
 
<code class="descclassname">os.</code><code class="descname">EX_USAGE</code><a class="headerlink" href="#os.EX_USAGE" title="Permalink to this definition">¶</a></dt>
1838
 
<dd><p>Exit code that means the command was used incorrectly, such as when the wrong
1839
 
number of arguments are given.</p>
1840
 
<p>Availability: Unix.</p>
1841
 
<div class="versionadded">
1842
 
<p><span class="versionmodified">New in version 2.3.</span></p>
1843
 
</div>
1844
 
</dd></dl>
1845
 
 
1846
 
<dl class="data">
1847
 
<dt id="os.EX_DATAERR">
1848
 
<code class="descclassname">os.</code><code class="descname">EX_DATAERR</code><a class="headerlink" href="#os.EX_DATAERR" title="Permalink to this definition">¶</a></dt>
1849
 
<dd><p>Exit code that means the input data was incorrect.</p>
1850
 
<p>Availability: Unix.</p>
1851
 
<div class="versionadded">
1852
 
<p><span class="versionmodified">New in version 2.3.</span></p>
1853
 
</div>
1854
 
</dd></dl>
1855
 
 
1856
 
<dl class="data">
1857
 
<dt id="os.EX_NOINPUT">
1858
 
<code class="descclassname">os.</code><code class="descname">EX_NOINPUT</code><a class="headerlink" href="#os.EX_NOINPUT" title="Permalink to this definition">¶</a></dt>
1859
 
<dd><p>Exit code that means an input file did not exist or was not readable.</p>
1860
 
<p>Availability: Unix.</p>
1861
 
<div class="versionadded">
1862
 
<p><span class="versionmodified">New in version 2.3.</span></p>
1863
 
</div>
1864
 
</dd></dl>
1865
 
 
1866
 
<dl class="data">
1867
 
<dt id="os.EX_NOUSER">
1868
 
<code class="descclassname">os.</code><code class="descname">EX_NOUSER</code><a class="headerlink" href="#os.EX_NOUSER" title="Permalink to this definition">¶</a></dt>
1869
 
<dd><p>Exit code that means a specified user did not exist.</p>
1870
 
<p>Availability: Unix.</p>
1871
 
<div class="versionadded">
1872
 
<p><span class="versionmodified">New in version 2.3.</span></p>
1873
 
</div>
1874
 
</dd></dl>
1875
 
 
1876
 
<dl class="data">
1877
 
<dt id="os.EX_NOHOST">
1878
 
<code class="descclassname">os.</code><code class="descname">EX_NOHOST</code><a class="headerlink" href="#os.EX_NOHOST" title="Permalink to this definition">¶</a></dt>
1879
 
<dd><p>Exit code that means a specified host did not exist.</p>
1880
 
<p>Availability: Unix.</p>
1881
 
<div class="versionadded">
1882
 
<p><span class="versionmodified">New in version 2.3.</span></p>
1883
 
</div>
1884
 
</dd></dl>
1885
 
 
1886
 
<dl class="data">
1887
 
<dt id="os.EX_UNAVAILABLE">
1888
 
<code class="descclassname">os.</code><code class="descname">EX_UNAVAILABLE</code><a class="headerlink" href="#os.EX_UNAVAILABLE" title="Permalink to this definition">¶</a></dt>
1889
 
<dd><p>Exit code that means that a required service is unavailable.</p>
1890
 
<p>Availability: Unix.</p>
1891
 
<div class="versionadded">
1892
 
<p><span class="versionmodified">New in version 2.3.</span></p>
1893
 
</div>
1894
 
</dd></dl>
1895
 
 
1896
 
<dl class="data">
1897
 
<dt id="os.EX_SOFTWARE">
1898
 
<code class="descclassname">os.</code><code class="descname">EX_SOFTWARE</code><a class="headerlink" href="#os.EX_SOFTWARE" title="Permalink to this definition">¶</a></dt>
1899
 
<dd><p>Exit code that means an internal software error was detected.</p>
1900
 
<p>Availability: Unix.</p>
1901
 
<div class="versionadded">
1902
 
<p><span class="versionmodified">New in version 2.3.</span></p>
1903
 
</div>
1904
 
</dd></dl>
1905
 
 
1906
 
<dl class="data">
1907
 
<dt id="os.EX_OSERR">
1908
 
<code class="descclassname">os.</code><code class="descname">EX_OSERR</code><a class="headerlink" href="#os.EX_OSERR" title="Permalink to this definition">¶</a></dt>
1909
 
<dd><p>Exit code that means an operating system error was detected, such as the
1910
 
inability to fork or create a pipe.</p>
1911
 
<p>Availability: Unix.</p>
1912
 
<div class="versionadded">
1913
 
<p><span class="versionmodified">New in version 2.3.</span></p>
1914
 
</div>
1915
 
</dd></dl>
1916
 
 
1917
 
<dl class="data">
1918
 
<dt id="os.EX_OSFILE">
1919
 
<code class="descclassname">os.</code><code class="descname">EX_OSFILE</code><a class="headerlink" href="#os.EX_OSFILE" title="Permalink to this definition">¶</a></dt>
1920
 
<dd><p>Exit code that means some system file did not exist, could not be opened, or had
1921
 
some other kind of error.</p>
1922
 
<p>Availability: Unix.</p>
1923
 
<div class="versionadded">
1924
 
<p><span class="versionmodified">New in version 2.3.</span></p>
1925
 
</div>
1926
 
</dd></dl>
1927
 
 
1928
 
<dl class="data">
1929
 
<dt id="os.EX_CANTCREAT">
1930
 
<code class="descclassname">os.</code><code class="descname">EX_CANTCREAT</code><a class="headerlink" href="#os.EX_CANTCREAT" title="Permalink to this definition">¶</a></dt>
1931
 
<dd><p>Exit code that means a user specified output file could not be created.</p>
1932
 
<p>Availability: Unix.</p>
1933
 
<div class="versionadded">
1934
 
<p><span class="versionmodified">New in version 2.3.</span></p>
1935
 
</div>
1936
 
</dd></dl>
1937
 
 
1938
 
<dl class="data">
1939
 
<dt id="os.EX_IOERR">
1940
 
<code class="descclassname">os.</code><code class="descname">EX_IOERR</code><a class="headerlink" href="#os.EX_IOERR" title="Permalink to this definition">¶</a></dt>
1941
 
<dd><p>Exit code that means that an error occurred while doing I/O on some file.</p>
1942
 
<p>Availability: Unix.</p>
1943
 
<div class="versionadded">
1944
 
<p><span class="versionmodified">New in version 2.3.</span></p>
1945
 
</div>
1946
 
</dd></dl>
1947
 
 
1948
 
<dl class="data">
1949
 
<dt id="os.EX_TEMPFAIL">
1950
 
<code class="descclassname">os.</code><code class="descname">EX_TEMPFAIL</code><a class="headerlink" href="#os.EX_TEMPFAIL" title="Permalink to this definition">¶</a></dt>
1951
 
<dd><p>Exit code that means a temporary failure occurred.  This indicates something
1952
 
that may not really be an error, such as a network connection that couldn&#8217;t be
1953
 
made during a retryable operation.</p>
1954
 
<p>Availability: Unix.</p>
1955
 
<div class="versionadded">
1956
 
<p><span class="versionmodified">New in version 2.3.</span></p>
1957
 
</div>
1958
 
</dd></dl>
1959
 
 
1960
 
<dl class="data">
1961
 
<dt id="os.EX_PROTOCOL">
1962
 
<code class="descclassname">os.</code><code class="descname">EX_PROTOCOL</code><a class="headerlink" href="#os.EX_PROTOCOL" title="Permalink to this definition">¶</a></dt>
1963
 
<dd><p>Exit code that means that a protocol exchange was illegal, invalid, or not
1964
 
understood.</p>
1965
 
<p>Availability: Unix.</p>
1966
 
<div class="versionadded">
1967
 
<p><span class="versionmodified">New in version 2.3.</span></p>
1968
 
</div>
1969
 
</dd></dl>
1970
 
 
1971
 
<dl class="data">
1972
 
<dt id="os.EX_NOPERM">
1973
 
<code class="descclassname">os.</code><code class="descname">EX_NOPERM</code><a class="headerlink" href="#os.EX_NOPERM" title="Permalink to this definition">¶</a></dt>
1974
 
<dd><p>Exit code that means that there were insufficient permissions to perform the
1975
 
operation (but not intended for file system problems).</p>
1976
 
<p>Availability: Unix.</p>
1977
 
<div class="versionadded">
1978
 
<p><span class="versionmodified">New in version 2.3.</span></p>
1979
 
</div>
1980
 
</dd></dl>
1981
 
 
1982
 
<dl class="data">
1983
 
<dt id="os.EX_CONFIG">
1984
 
<code class="descclassname">os.</code><code class="descname">EX_CONFIG</code><a class="headerlink" href="#os.EX_CONFIG" title="Permalink to this definition">¶</a></dt>
1985
 
<dd><p>Exit code that means that some kind of configuration error occurred.</p>
1986
 
<p>Availability: Unix.</p>
1987
 
<div class="versionadded">
1988
 
<p><span class="versionmodified">New in version 2.3.</span></p>
1989
 
</div>
1990
 
</dd></dl>
1991
 
 
1992
 
<dl class="data">
1993
 
<dt id="os.EX_NOTFOUND">
1994
 
<code class="descclassname">os.</code><code class="descname">EX_NOTFOUND</code><a class="headerlink" href="#os.EX_NOTFOUND" title="Permalink to this definition">¶</a></dt>
1995
 
<dd><p>Exit code that means something like &#8220;an entry was not found&#8221;.</p>
1996
 
<p>Availability: Unix.</p>
1997
 
<div class="versionadded">
1998
 
<p><span class="versionmodified">New in version 2.3.</span></p>
1999
 
</div>
2000
 
</dd></dl>
2001
 
 
2002
 
<dl class="function">
2003
 
<dt id="os.fork">
2004
 
<code class="descclassname">os.</code><code class="descname">fork</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.fork" title="Permalink to this definition">¶</a></dt>
2005
 
<dd><p>Fork a child process.  Return <code class="docutils literal"><span class="pre">0</span></code> in the child and the child&#8217;s process id in the
2006
 
parent.  If an error occurs <a class="reference internal" href="exceptions.html#exceptions.OSError" title="exceptions.OSError"><code class="xref py py-exc docutils literal"><span class="pre">OSError</span></code></a> is raised.</p>
2007
 
<p>Note that some platforms including FreeBSD &lt;= 6.3, Cygwin and OS/2 EMX have
2008
 
known issues when using fork() from a thread.</p>
2009
 
<div class="admonition warning">
2010
 
<p class="first admonition-title">Warning</p>
2011
 
<p class="last">See <a class="reference internal" href="ssl.html#module-ssl" title="ssl: TLS/SSL wrapper for socket objects"><code class="xref py py-mod docutils literal"><span class="pre">ssl</span></code></a> for applications that use the SSL module with fork().</p>
2012
 
</div>
2013
 
<p>Availability: Unix.</p>
2014
 
</dd></dl>
2015
 
 
2016
 
<dl class="function">
2017
 
<dt id="os.forkpty">
2018
 
<code class="descclassname">os.</code><code class="descname">forkpty</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.forkpty" title="Permalink to this definition">¶</a></dt>
2019
 
<dd><p>Fork a child process, using a new pseudo-terminal as the child&#8217;s controlling
2020
 
terminal. Return a pair of <code class="docutils literal"><span class="pre">(pid,</span> <span class="pre">fd)</span></code>, where <em>pid</em> is <code class="docutils literal"><span class="pre">0</span></code> in the child, the
2021
 
new child&#8217;s process id in the parent, and <em>fd</em> is the file descriptor of the
2022
 
master end of the pseudo-terminal.  For a more portable approach, use the
2023
 
<a class="reference internal" href="pty.html#module-pty" title="pty: Pseudo-Terminal Handling for Linux. (Linux)"><code class="xref py py-mod docutils literal"><span class="pre">pty</span></code></a> module.  If an error occurs <a class="reference internal" href="exceptions.html#exceptions.OSError" title="exceptions.OSError"><code class="xref py py-exc docutils literal"><span class="pre">OSError</span></code></a> is raised.</p>
2024
 
<p>Availability: some flavors of Unix.</p>
2025
 
</dd></dl>
2026
 
 
2027
 
<dl class="function">
2028
 
<dt id="os.kill">
2029
 
<code class="descclassname">os.</code><code class="descname">kill</code><span class="sig-paren">(</span><em>pid</em>, <em>sig</em><span class="sig-paren">)</span><a class="headerlink" href="#os.kill" title="Permalink to this definition">¶</a></dt>
2030
 
<dd><p id="index-24">Send signal <em>sig</em> to the process <em>pid</em>.  Constants for the specific signals
2031
 
available on the host platform are defined in the <a class="reference internal" href="signal.html#module-signal" title="signal: Set handlers for asynchronous events."><code class="xref py py-mod docutils literal"><span class="pre">signal</span></code></a> module.</p>
2032
 
<p>Windows: The <a class="reference internal" href="signal.html#signal.CTRL_C_EVENT" title="signal.CTRL_C_EVENT"><code class="xref py py-data docutils literal"><span class="pre">signal.CTRL_C_EVENT</span></code></a> and
2033
 
<a class="reference internal" href="signal.html#signal.CTRL_BREAK_EVENT" title="signal.CTRL_BREAK_EVENT"><code class="xref py py-data docutils literal"><span class="pre">signal.CTRL_BREAK_EVENT</span></code></a> signals are special signals which can
2034
 
only be sent to console processes which share a common console window,
2035
 
e.g., some subprocesses. Any other value for <em>sig</em> will cause the process
2036
 
to be unconditionally killed by the TerminateProcess API, and the exit code
2037
 
will be set to <em>sig</em>. The Windows version of <a class="reference internal" href="#os.kill" title="os.kill"><code class="xref py py-func docutils literal"><span class="pre">kill()</span></code></a> additionally takes
2038
 
process handles to be killed.</p>
2039
 
<div class="versionadded">
2040
 
<p><span class="versionmodified">New in version 2.7: </span>Windows support</p>
2041
 
</div>
2042
 
</dd></dl>
2043
 
 
2044
 
<dl class="function">
2045
 
<dt id="os.killpg">
2046
 
<code class="descclassname">os.</code><code class="descname">killpg</code><span class="sig-paren">(</span><em>pgid</em>, <em>sig</em><span class="sig-paren">)</span><a class="headerlink" href="#os.killpg" title="Permalink to this definition">¶</a></dt>
2047
 
<dd><p id="index-25">Send the signal <em>sig</em> to the process group <em>pgid</em>.</p>
2048
 
<p>Availability: Unix.</p>
2049
 
<div class="versionadded">
2050
 
<p><span class="versionmodified">New in version 2.3.</span></p>
2051
 
</div>
2052
 
</dd></dl>
2053
 
 
2054
 
<dl class="function">
2055
 
<dt id="os.nice">
2056
 
<code class="descclassname">os.</code><code class="descname">nice</code><span class="sig-paren">(</span><em>increment</em><span class="sig-paren">)</span><a class="headerlink" href="#os.nice" title="Permalink to this definition">¶</a></dt>
2057
 
<dd><p>Add <em>increment</em> to the process&#8217;s &#8220;niceness&#8221;.  Return the new niceness.</p>
2058
 
<p>Availability: Unix.</p>
2059
 
</dd></dl>
2060
 
 
2061
 
<dl class="function">
2062
 
<dt id="os.plock">
2063
 
<code class="descclassname">os.</code><code class="descname">plock</code><span class="sig-paren">(</span><em>op</em><span class="sig-paren">)</span><a class="headerlink" href="#os.plock" title="Permalink to this definition">¶</a></dt>
2064
 
<dd><p>Lock program segments into memory.  The value of <em>op</em> (defined in
2065
 
<code class="docutils literal"><span class="pre">&lt;sys/lock.h&gt;</span></code>) determines which segments are locked.</p>
2066
 
<p>Availability: Unix.</p>
2067
 
</dd></dl>
2068
 
 
2069
 
<dl class="function">
2070
 
<dt>
2071
 
<code class="descclassname">os.</code><code class="descname">popen</code><span class="sig-paren">(</span><em>...</em><span class="sig-paren">)</span></dt>
2072
 
<dt>
2073
 
<code class="descclassname">os.</code><code class="descname">popen2</code><span class="sig-paren">(</span><em>...</em><span class="sig-paren">)</span></dt>
2074
 
<dt>
2075
 
<code class="descclassname">os.</code><code class="descname">popen3</code><span class="sig-paren">(</span><em>...</em><span class="sig-paren">)</span></dt>
2076
 
<dt>
2077
 
<code class="descclassname">os.</code><code class="descname">popen4</code><span class="sig-paren">(</span><em>...</em><span class="sig-paren">)</span></dt>
2078
 
<dd><p>Run child processes, returning opened pipes for communications.  These functions
2079
 
are described in section <a class="reference internal" href="#os-newstreams"><span>File Object Creation</span></a>.</p>
2080
 
</dd></dl>
2081
 
 
2082
 
<dl class="function">
2083
 
<dt id="os.spawnl">
2084
 
<code class="descclassname">os.</code><code class="descname">spawnl</code><span class="sig-paren">(</span><em>mode</em>, <em>path</em>, <em>...</em><span class="sig-paren">)</span><a class="headerlink" href="#os.spawnl" title="Permalink to this definition">¶</a></dt>
2085
 
<dt id="os.spawnle">
2086
 
<code class="descclassname">os.</code><code class="descname">spawnle</code><span class="sig-paren">(</span><em>mode</em>, <em>path</em>, <em>...</em>, <em>env</em><span class="sig-paren">)</span><a class="headerlink" href="#os.spawnle" title="Permalink to this definition">¶</a></dt>
2087
 
<dt id="os.spawnlp">
2088
 
<code class="descclassname">os.</code><code class="descname">spawnlp</code><span class="sig-paren">(</span><em>mode</em>, <em>file</em>, <em>...</em><span class="sig-paren">)</span><a class="headerlink" href="#os.spawnlp" title="Permalink to this definition">¶</a></dt>
2089
 
<dt id="os.spawnlpe">
2090
 
<code class="descclassname">os.</code><code class="descname">spawnlpe</code><span class="sig-paren">(</span><em>mode</em>, <em>file</em>, <em>...</em>, <em>env</em><span class="sig-paren">)</span><a class="headerlink" href="#os.spawnlpe" title="Permalink to this definition">¶</a></dt>
2091
 
<dt id="os.spawnv">
2092
 
<code class="descclassname">os.</code><code class="descname">spawnv</code><span class="sig-paren">(</span><em>mode</em>, <em>path</em>, <em>args</em><span class="sig-paren">)</span><a class="headerlink" href="#os.spawnv" title="Permalink to this definition">¶</a></dt>
2093
 
<dt id="os.spawnve">
2094
 
<code class="descclassname">os.</code><code class="descname">spawnve</code><span class="sig-paren">(</span><em>mode</em>, <em>path</em>, <em>args</em>, <em>env</em><span class="sig-paren">)</span><a class="headerlink" href="#os.spawnve" title="Permalink to this definition">¶</a></dt>
2095
 
<dt id="os.spawnvp">
2096
 
<code class="descclassname">os.</code><code class="descname">spawnvp</code><span class="sig-paren">(</span><em>mode</em>, <em>file</em>, <em>args</em><span class="sig-paren">)</span><a class="headerlink" href="#os.spawnvp" title="Permalink to this definition">¶</a></dt>
2097
 
<dt id="os.spawnvpe">
2098
 
<code class="descclassname">os.</code><code class="descname">spawnvpe</code><span class="sig-paren">(</span><em>mode</em>, <em>file</em>, <em>args</em>, <em>env</em><span class="sig-paren">)</span><a class="headerlink" href="#os.spawnvpe" title="Permalink to this definition">¶</a></dt>
2099
 
<dd><p>Execute the program <em>path</em> in a new process.</p>
2100
 
<p>(Note that the <a class="reference internal" href="subprocess.html#module-subprocess" title="subprocess: Subprocess management."><code class="xref py py-mod docutils literal"><span class="pre">subprocess</span></code></a> module provides more powerful facilities for
2101
 
spawning new processes and retrieving their results; using that module is
2102
 
preferable to using these functions.  Check especially the
2103
 
<a class="reference internal" href="subprocess.html#subprocess-replacements"><span>Replacing Older Functions with the subprocess Module</span></a> section.)</p>
2104
 
<p>If <em>mode</em> is <a class="reference internal" href="#os.P_NOWAIT" title="os.P_NOWAIT"><code class="xref py py-const docutils literal"><span class="pre">P_NOWAIT</span></code></a>, this function returns the process id of the new
2105
 
process; if <em>mode</em> is <a class="reference internal" href="#os.P_WAIT" title="os.P_WAIT"><code class="xref py py-const docutils literal"><span class="pre">P_WAIT</span></code></a>, returns the process&#8217;s exit code if it
2106
 
exits normally, or <code class="docutils literal"><span class="pre">-signal</span></code>, where <em>signal</em> is the signal that killed the
2107
 
process.  On Windows, the process id will actually be the process handle, so can
2108
 
be used with the <a class="reference internal" href="#os.waitpid" title="os.waitpid"><code class="xref py py-func docutils literal"><span class="pre">waitpid()</span></code></a> function.</p>
2109
 
<p>The &#8220;l&#8221; and &#8220;v&#8221; variants of the <a class="reference internal" href="#os.spawnl" title="os.spawnl"><code class="xref py py-func docutils literal"><span class="pre">spawn*</span></code></a> functions differ in how
2110
 
command-line arguments are passed.  The &#8220;l&#8221; variants are perhaps the easiest
2111
 
to work with if the number of parameters is fixed when the code is written; the
2112
 
individual parameters simply become additional parameters to the
2113
 
<code class="xref py py-func docutils literal"><span class="pre">spawnl*()</span></code> functions.  The &#8220;v&#8221; variants are good when the number of
2114
 
parameters is variable, with the arguments being passed in a list or tuple as
2115
 
the <em>args</em> parameter.  In either case, the arguments to the child process must
2116
 
start with the name of the command being run.</p>
2117
 
<p>The variants which include a second &#8220;p&#8221; near the end (<a class="reference internal" href="#os.spawnlp" title="os.spawnlp"><code class="xref py py-func docutils literal"><span class="pre">spawnlp()</span></code></a>,
2118
 
<a class="reference internal" href="#os.spawnlpe" title="os.spawnlpe"><code class="xref py py-func docutils literal"><span class="pre">spawnlpe()</span></code></a>, <a class="reference internal" href="#os.spawnvp" title="os.spawnvp"><code class="xref py py-func docutils literal"><span class="pre">spawnvp()</span></code></a>, and <a class="reference internal" href="#os.spawnvpe" title="os.spawnvpe"><code class="xref py py-func docutils literal"><span class="pre">spawnvpe()</span></code></a>) will use the
2119
 
<span class="target" id="index-26"></span><code class="xref std std-envvar docutils literal"><span class="pre">PATH</span></code> environment variable to locate the program <em>file</em>.  When the
2120
 
environment is being replaced (using one of the <a class="reference internal" href="#os.spawnl" title="os.spawnl"><code class="xref py py-func docutils literal"><span class="pre">spawn*e</span></code></a> variants,
2121
 
discussed in the next paragraph), the new environment is used as the source of
2122
 
the <span class="target" id="index-27"></span><code class="xref std std-envvar docutils literal"><span class="pre">PATH</span></code> variable.  The other variants, <a class="reference internal" href="#os.spawnl" title="os.spawnl"><code class="xref py py-func docutils literal"><span class="pre">spawnl()</span></code></a>,
2123
 
<a class="reference internal" href="#os.spawnle" title="os.spawnle"><code class="xref py py-func docutils literal"><span class="pre">spawnle()</span></code></a>, <a class="reference internal" href="#os.spawnv" title="os.spawnv"><code class="xref py py-func docutils literal"><span class="pre">spawnv()</span></code></a>, and <a class="reference internal" href="#os.spawnve" title="os.spawnve"><code class="xref py py-func docutils literal"><span class="pre">spawnve()</span></code></a>, will not use the
2124
 
<span class="target" id="index-28"></span><code class="xref std std-envvar docutils literal"><span class="pre">PATH</span></code> variable to locate the executable; <em>path</em> must contain an
2125
 
appropriate absolute or relative path.</p>
2126
 
<p>For <a class="reference internal" href="#os.spawnle" title="os.spawnle"><code class="xref py py-func docutils literal"><span class="pre">spawnle()</span></code></a>, <a class="reference internal" href="#os.spawnlpe" title="os.spawnlpe"><code class="xref py py-func docutils literal"><span class="pre">spawnlpe()</span></code></a>, <a class="reference internal" href="#os.spawnve" title="os.spawnve"><code class="xref py py-func docutils literal"><span class="pre">spawnve()</span></code></a>, and <a class="reference internal" href="#os.spawnvpe" title="os.spawnvpe"><code class="xref py py-func docutils literal"><span class="pre">spawnvpe()</span></code></a>
2127
 
(note that these all end in &#8220;e&#8221;), the <em>env</em> parameter must be a mapping
2128
 
which is used to define the environment variables for the new process (they are
2129
 
used instead of the current process&#8217; environment); the functions
2130
 
<a class="reference internal" href="#os.spawnl" title="os.spawnl"><code class="xref py py-func docutils literal"><span class="pre">spawnl()</span></code></a>, <a class="reference internal" href="#os.spawnlp" title="os.spawnlp"><code class="xref py py-func docutils literal"><span class="pre">spawnlp()</span></code></a>, <a class="reference internal" href="#os.spawnv" title="os.spawnv"><code class="xref py py-func docutils literal"><span class="pre">spawnv()</span></code></a>, and <a class="reference internal" href="#os.spawnvp" title="os.spawnvp"><code class="xref py py-func docutils literal"><span class="pre">spawnvp()</span></code></a> all cause
2131
 
the new process to inherit the environment of the current process.  Note that
2132
 
keys and values in the <em>env</em> dictionary must be strings; invalid keys or
2133
 
values will cause the function to fail, with a return value of <code class="docutils literal"><span class="pre">127</span></code>.</p>
2134
 
<p>As an example, the following calls to <a class="reference internal" href="#os.spawnlp" title="os.spawnlp"><code class="xref py py-func docutils literal"><span class="pre">spawnlp()</span></code></a> and <a class="reference internal" href="#os.spawnvpe" title="os.spawnvpe"><code class="xref py py-func docutils literal"><span class="pre">spawnvpe()</span></code></a> are
2135
 
equivalent:</p>
2136
 
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">os</span>
2137
 
<span class="n">os</span><span class="o">.</span><span class="n">spawnlp</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">P_WAIT</span><span class="p">,</span> <span class="s1">&#39;cp&#39;</span><span class="p">,</span> <span class="s1">&#39;cp&#39;</span><span class="p">,</span> <span class="s1">&#39;index.html&#39;</span><span class="p">,</span> <span class="s1">&#39;/dev/null&#39;</span><span class="p">)</span>
2138
 
 
2139
 
<span class="n">L</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;cp&#39;</span><span class="p">,</span> <span class="s1">&#39;index.html&#39;</span><span class="p">,</span> <span class="s1">&#39;/dev/null&#39;</span><span class="p">]</span>
2140
 
<span class="n">os</span><span class="o">.</span><span class="n">spawnvpe</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">P_WAIT</span><span class="p">,</span> <span class="s1">&#39;cp&#39;</span><span class="p">,</span> <span class="n">L</span><span class="p">,</span> <span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">)</span>
2141
 
</pre></div>
2142
 
</div>
2143
 
<p>Availability: Unix, Windows.  <a class="reference internal" href="#os.spawnlp" title="os.spawnlp"><code class="xref py py-func docutils literal"><span class="pre">spawnlp()</span></code></a>, <a class="reference internal" href="#os.spawnlpe" title="os.spawnlpe"><code class="xref py py-func docutils literal"><span class="pre">spawnlpe()</span></code></a>, <a class="reference internal" href="#os.spawnvp" title="os.spawnvp"><code class="xref py py-func docutils literal"><span class="pre">spawnvp()</span></code></a>
2144
 
and <a class="reference internal" href="#os.spawnvpe" title="os.spawnvpe"><code class="xref py py-func docutils literal"><span class="pre">spawnvpe()</span></code></a> are not available on Windows.  <a class="reference internal" href="#os.spawnle" title="os.spawnle"><code class="xref py py-func docutils literal"><span class="pre">spawnle()</span></code></a> and
2145
 
<a class="reference internal" href="#os.spawnve" title="os.spawnve"><code class="xref py py-func docutils literal"><span class="pre">spawnve()</span></code></a> are not thread-safe on Windows; we advise you to use the
2146
 
<a class="reference internal" href="subprocess.html#module-subprocess" title="subprocess: Subprocess management."><code class="xref py py-mod docutils literal"><span class="pre">subprocess</span></code></a> module instead.</p>
2147
 
<div class="versionadded">
2148
 
<p><span class="versionmodified">New in version 1.6.</span></p>
2149
 
</div>
2150
 
</dd></dl>
2151
 
 
2152
 
<dl class="data">
2153
 
<dt id="os.P_NOWAIT">
2154
 
<code class="descclassname">os.</code><code class="descname">P_NOWAIT</code><a class="headerlink" href="#os.P_NOWAIT" title="Permalink to this definition">¶</a></dt>
2155
 
<dt id="os.P_NOWAITO">
2156
 
<code class="descclassname">os.</code><code class="descname">P_NOWAITO</code><a class="headerlink" href="#os.P_NOWAITO" title="Permalink to this definition">¶</a></dt>
2157
 
<dd><p>Possible values for the <em>mode</em> parameter to the <a class="reference internal" href="#os.spawnl" title="os.spawnl"><code class="xref py py-func docutils literal"><span class="pre">spawn*</span></code></a> family of
2158
 
functions.  If either of these values is given, the <code class="xref py py-func docutils literal"><span class="pre">spawn*()</span></code> functions
2159
 
will return as soon as the new process has been created, with the process id as
2160
 
the return value.</p>
2161
 
<p>Availability: Unix, Windows.</p>
2162
 
<div class="versionadded">
2163
 
<p><span class="versionmodified">New in version 1.6.</span></p>
2164
 
</div>
2165
 
</dd></dl>
2166
 
 
2167
 
<dl class="data">
2168
 
<dt id="os.P_WAIT">
2169
 
<code class="descclassname">os.</code><code class="descname">P_WAIT</code><a class="headerlink" href="#os.P_WAIT" title="Permalink to this definition">¶</a></dt>
2170
 
<dd><p>Possible value for the <em>mode</em> parameter to the <a class="reference internal" href="#os.spawnl" title="os.spawnl"><code class="xref py py-func docutils literal"><span class="pre">spawn*</span></code></a> family of
2171
 
functions.  If this is given as <em>mode</em>, the <code class="xref py py-func docutils literal"><span class="pre">spawn*()</span></code> functions will not
2172
 
return until the new process has run to completion and will return the exit code
2173
 
of the process the run is successful, or <code class="docutils literal"><span class="pre">-signal</span></code> if a signal kills the
2174
 
process.</p>
2175
 
<p>Availability: Unix, Windows.</p>
2176
 
<div class="versionadded">
2177
 
<p><span class="versionmodified">New in version 1.6.</span></p>
2178
 
</div>
2179
 
</dd></dl>
2180
 
 
2181
 
<dl class="data">
2182
 
<dt id="os.P_DETACH">
2183
 
<code class="descclassname">os.</code><code class="descname">P_DETACH</code><a class="headerlink" href="#os.P_DETACH" title="Permalink to this definition">¶</a></dt>
2184
 
<dt id="os.P_OVERLAY">
2185
 
<code class="descclassname">os.</code><code class="descname">P_OVERLAY</code><a class="headerlink" href="#os.P_OVERLAY" title="Permalink to this definition">¶</a></dt>
2186
 
<dd><p>Possible values for the <em>mode</em> parameter to the <a class="reference internal" href="#os.spawnl" title="os.spawnl"><code class="xref py py-func docutils literal"><span class="pre">spawn*</span></code></a> family of
2187
 
functions.  These are less portable than those listed above. <a class="reference internal" href="#os.P_DETACH" title="os.P_DETACH"><code class="xref py py-const docutils literal"><span class="pre">P_DETACH</span></code></a>
2188
 
is similar to <a class="reference internal" href="#os.P_NOWAIT" title="os.P_NOWAIT"><code class="xref py py-const docutils literal"><span class="pre">P_NOWAIT</span></code></a>, but the new process is detached from the
2189
 
console of the calling process. If <a class="reference internal" href="#os.P_OVERLAY" title="os.P_OVERLAY"><code class="xref py py-const docutils literal"><span class="pre">P_OVERLAY</span></code></a> is used, the current
2190
 
process will be replaced; the <code class="xref py py-func docutils literal"><span class="pre">spawn*()</span></code> function will not return.</p>
2191
 
<p>Availability: Windows.</p>
2192
 
<div class="versionadded">
2193
 
<p><span class="versionmodified">New in version 1.6.</span></p>
2194
 
</div>
2195
 
</dd></dl>
2196
 
 
2197
 
<dl class="function">
2198
 
<dt id="os.startfile">
2199
 
<code class="descclassname">os.</code><code class="descname">startfile</code><span class="sig-paren">(</span><em>path</em><span class="optional">[</span>, <em>operation</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#os.startfile" title="Permalink to this definition">¶</a></dt>
2200
 
<dd><p>Start a file with its associated application.</p>
2201
 
<p>When <em>operation</em> is not specified or <code class="docutils literal"><span class="pre">'open'</span></code>, this acts like double-clicking
2202
 
the file in Windows Explorer, or giving the file name as an argument to the
2203
 
<strong class="program">start</strong> command from the interactive command shell: the file is opened
2204
 
with whatever application (if any) its extension is associated.</p>
2205
 
<p>When another <em>operation</em> is given, it must be a &#8220;command verb&#8221; that specifies
2206
 
what should be done with the file. Common verbs documented by Microsoft are
2207
 
<code class="docutils literal"><span class="pre">'print'</span></code> and  <code class="docutils literal"><span class="pre">'edit'</span></code> (to be used on files) as well as <code class="docutils literal"><span class="pre">'explore'</span></code> and
2208
 
<code class="docutils literal"><span class="pre">'find'</span></code> (to be used on directories).</p>
2209
 
<p><a class="reference internal" href="#os.startfile" title="os.startfile"><code class="xref py py-func docutils literal"><span class="pre">startfile()</span></code></a> returns as soon as the associated application is launched.
2210
 
There is no option to wait for the application to close, and no way to retrieve
2211
 
the application&#8217;s exit status.  The <em>path</em> parameter is relative to the current
2212
 
directory.  If you want to use an absolute path, make sure the first character
2213
 
is not a slash (<code class="docutils literal"><span class="pre">'/'</span></code>); the underlying Win32 <code class="xref c c-func docutils literal"><span class="pre">ShellExecute()</span></code> function
2214
 
doesn&#8217;t work if it is.  Use the <a class="reference internal" href="os.path.html#os.path.normpath" title="os.path.normpath"><code class="xref py py-func docutils literal"><span class="pre">os.path.normpath()</span></code></a> function to ensure that
2215
 
the path is properly encoded for Win32.</p>
2216
 
<p>Availability: Windows.</p>
2217
 
<div class="versionadded">
2218
 
<p><span class="versionmodified">New in version 2.0.</span></p>
2219
 
</div>
2220
 
<div class="versionadded">
2221
 
<p><span class="versionmodified">New in version 2.5: </span>The <em>operation</em> parameter.</p>
2222
 
</div>
2223
 
</dd></dl>
2224
 
 
2225
 
<dl class="function">
2226
 
<dt id="os.system">
2227
 
<code class="descclassname">os.</code><code class="descname">system</code><span class="sig-paren">(</span><em>command</em><span class="sig-paren">)</span><a class="headerlink" href="#os.system" title="Permalink to this definition">¶</a></dt>
2228
 
<dd><p>Execute the command (a string) in a subshell.  This is implemented by calling
2229
 
the Standard C function <code class="xref c c-func docutils literal"><span class="pre">system()</span></code>, and has the same limitations.
2230
 
Changes to <a class="reference internal" href="sys.html#sys.stdin" title="sys.stdin"><code class="xref py py-data docutils literal"><span class="pre">sys.stdin</span></code></a>, etc. are not reflected in the environment of the
2231
 
executed command.</p>
2232
 
<p>On Unix, the return value is the exit status of the process encoded in the
2233
 
format specified for <a class="reference internal" href="#os.wait" title="os.wait"><code class="xref py py-func docutils literal"><span class="pre">wait()</span></code></a>.  Note that POSIX does not specify the meaning
2234
 
of the return value of the C <code class="xref c c-func docutils literal"><span class="pre">system()</span></code> function, so the return value of
2235
 
the Python function is system-dependent.</p>
2236
 
<p>On Windows, the return value is that returned by the system shell after running
2237
 
<em>command</em>, given by the Windows environment variable <span class="target" id="index-29"></span><code class="xref std std-envvar docutils literal"><span class="pre">COMSPEC</span></code>: on
2238
 
<strong class="program">command.com</strong> systems (Windows 95, 98 and ME) this is always <code class="docutils literal"><span class="pre">0</span></code>; on
2239
 
<strong class="program">cmd.exe</strong> systems (Windows NT, 2000 and XP) this is the exit status of
2240
 
the command run; on systems using a non-native shell, consult your shell
2241
 
documentation.</p>
2242
 
<p>The <a class="reference internal" href="subprocess.html#module-subprocess" title="subprocess: Subprocess management."><code class="xref py py-mod docutils literal"><span class="pre">subprocess</span></code></a> module provides more powerful facilities for spawning new
2243
 
processes and retrieving their results; using that module is preferable to using
2244
 
this function.  See the
2245
 
<a class="reference internal" href="subprocess.html#subprocess-replacements"><span>Replacing Older Functions with the subprocess Module</span></a> section in the <a class="reference internal" href="subprocess.html#module-subprocess" title="subprocess: Subprocess management."><code class="xref py py-mod docutils literal"><span class="pre">subprocess</span></code></a> documentation
2246
 
for some helpful recipes.</p>
2247
 
<p>Availability: Unix, Windows.</p>
2248
 
</dd></dl>
2249
 
 
2250
 
<dl class="function">
2251
 
<dt id="os.times">
2252
 
<code class="descclassname">os.</code><code class="descname">times</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.times" title="Permalink to this definition">¶</a></dt>
2253
 
<dd><p>Return a 5-tuple of floating point numbers indicating accumulated (processor
2254
 
or other) times, in seconds.  The items are: user time, system time,
2255
 
children&#8217;s user time, children&#8217;s system time, and elapsed real time since a
2256
 
fixed point in the past, in that order.  See the Unix manual page
2257
 
<em class="manpage">times(2)</em> or the corresponding Windows Platform API documentation.
2258
 
On Windows, only the first two items are filled, the others are zero.</p>
2259
 
<p>Availability: Unix, Windows</p>
2260
 
</dd></dl>
2261
 
 
2262
 
<dl class="function">
2263
 
<dt id="os.wait">
2264
 
<code class="descclassname">os.</code><code class="descname">wait</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.wait" title="Permalink to this definition">¶</a></dt>
2265
 
<dd><p>Wait for completion of a child process, and return a tuple containing its pid
2266
 
and exit status indication: a 16-bit number, whose low byte is the signal number
2267
 
that killed the process, and whose high byte is the exit status (if the signal
2268
 
number is zero); the high bit of the low byte is set if a core file was
2269
 
produced.</p>
2270
 
<p>Availability: Unix.</p>
2271
 
</dd></dl>
2272
 
 
2273
 
<dl class="function">
2274
 
<dt id="os.waitpid">
2275
 
<code class="descclassname">os.</code><code class="descname">waitpid</code><span class="sig-paren">(</span><em>pid</em>, <em>options</em><span class="sig-paren">)</span><a class="headerlink" href="#os.waitpid" title="Permalink to this definition">¶</a></dt>
2276
 
<dd><p>The details of this function differ on Unix and Windows.</p>
2277
 
<p>On Unix: Wait for completion of a child process given by process id <em>pid</em>, and
2278
 
return a tuple containing its process id and exit status indication (encoded as
2279
 
for <a class="reference internal" href="#os.wait" title="os.wait"><code class="xref py py-func docutils literal"><span class="pre">wait()</span></code></a>).  The semantics of the call are affected by the value of the
2280
 
integer <em>options</em>, which should be <code class="docutils literal"><span class="pre">0</span></code> for normal operation.</p>
2281
 
<p>If <em>pid</em> is greater than <code class="docutils literal"><span class="pre">0</span></code>, <a class="reference internal" href="#os.waitpid" title="os.waitpid"><code class="xref py py-func docutils literal"><span class="pre">waitpid()</span></code></a> requests status information for
2282
 
that specific process.  If <em>pid</em> is <code class="docutils literal"><span class="pre">0</span></code>, the request is for the status of any
2283
 
child in the process group of the current process.  If <em>pid</em> is <code class="docutils literal"><span class="pre">-1</span></code>, the
2284
 
request pertains to any child of the current process.  If <em>pid</em> is less than
2285
 
<code class="docutils literal"><span class="pre">-1</span></code>, status is requested for any process in the process group <code class="docutils literal"><span class="pre">-pid</span></code> (the
2286
 
absolute value of <em>pid</em>).</p>
2287
 
<p>An <a class="reference internal" href="exceptions.html#exceptions.OSError" title="exceptions.OSError"><code class="xref py py-exc docutils literal"><span class="pre">OSError</span></code></a> is raised with the value of errno when the syscall
2288
 
returns -1.</p>
2289
 
<p>On Windows: Wait for completion of a process given by process handle <em>pid</em>, and
2290
 
return a tuple containing <em>pid</em>, and its exit status shifted left by 8 bits
2291
 
(shifting makes cross-platform use of the function easier). A <em>pid</em> less than or
2292
 
equal to <code class="docutils literal"><span class="pre">0</span></code> has no special meaning on Windows, and raises an exception. The
2293
 
value of integer <em>options</em> has no effect. <em>pid</em> can refer to any process whose
2294
 
id is known, not necessarily a child process. The <a class="reference internal" href="#os.spawnl" title="os.spawnl"><code class="xref py py-func docutils literal"><span class="pre">spawn*</span></code></a>
2295
 
functions called with <a class="reference internal" href="#os.P_NOWAIT" title="os.P_NOWAIT"><code class="xref py py-const docutils literal"><span class="pre">P_NOWAIT</span></code></a> return suitable process handles.</p>
2296
 
</dd></dl>
2297
 
 
2298
 
<dl class="function">
2299
 
<dt id="os.wait3">
2300
 
<code class="descclassname">os.</code><code class="descname">wait3</code><span class="sig-paren">(</span><em>options</em><span class="sig-paren">)</span><a class="headerlink" href="#os.wait3" title="Permalink to this definition">¶</a></dt>
2301
 
<dd><p>Similar to <a class="reference internal" href="#os.waitpid" title="os.waitpid"><code class="xref py py-func docutils literal"><span class="pre">waitpid()</span></code></a>, except no process id argument is given and a
2302
 
3-element tuple containing the child&#8217;s process id, exit status indication, and
2303
 
resource usage information is returned.  Refer to <a class="reference internal" href="resource.html#module-resource" title="resource: An interface to provide resource usage information on the current process. (Unix)"><code class="xref py py-mod docutils literal"><span class="pre">resource</span></code></a>.<a class="reference internal" href="resource.html#resource.getrusage" title="resource.getrusage"><code class="xref py py-func docutils literal"><span class="pre">getrusage()</span></code></a> for details on resource usage information.  The
2304
 
option argument is the same as that provided to <a class="reference internal" href="#os.waitpid" title="os.waitpid"><code class="xref py py-func docutils literal"><span class="pre">waitpid()</span></code></a> and
2305
 
<a class="reference internal" href="#os.wait4" title="os.wait4"><code class="xref py py-func docutils literal"><span class="pre">wait4()</span></code></a>.</p>
2306
 
<p>Availability: Unix.</p>
2307
 
<div class="versionadded">
2308
 
<p><span class="versionmodified">New in version 2.5.</span></p>
2309
 
</div>
2310
 
</dd></dl>
2311
 
 
2312
 
<dl class="function">
2313
 
<dt id="os.wait4">
2314
 
<code class="descclassname">os.</code><code class="descname">wait4</code><span class="sig-paren">(</span><em>pid</em>, <em>options</em><span class="sig-paren">)</span><a class="headerlink" href="#os.wait4" title="Permalink to this definition">¶</a></dt>
2315
 
<dd><p>Similar to <a class="reference internal" href="#os.waitpid" title="os.waitpid"><code class="xref py py-func docutils literal"><span class="pre">waitpid()</span></code></a>, except a 3-element tuple, containing the child&#8217;s
2316
 
process id, exit status indication, and resource usage information is returned.
2317
 
Refer to <a class="reference internal" href="resource.html#module-resource" title="resource: An interface to provide resource usage information on the current process. (Unix)"><code class="xref py py-mod docutils literal"><span class="pre">resource</span></code></a>.<a class="reference internal" href="resource.html#resource.getrusage" title="resource.getrusage"><code class="xref py py-func docutils literal"><span class="pre">getrusage()</span></code></a> for details on
2318
 
resource usage information.  The arguments to <a class="reference internal" href="#os.wait4" title="os.wait4"><code class="xref py py-func docutils literal"><span class="pre">wait4()</span></code></a> are the same as
2319
 
those provided to <a class="reference internal" href="#os.waitpid" title="os.waitpid"><code class="xref py py-func docutils literal"><span class="pre">waitpid()</span></code></a>.</p>
2320
 
<p>Availability: Unix.</p>
2321
 
<div class="versionadded">
2322
 
<p><span class="versionmodified">New in version 2.5.</span></p>
2323
 
</div>
2324
 
</dd></dl>
2325
 
 
2326
 
<dl class="data">
2327
 
<dt id="os.WNOHANG">
2328
 
<code class="descclassname">os.</code><code class="descname">WNOHANG</code><a class="headerlink" href="#os.WNOHANG" title="Permalink to this definition">¶</a></dt>
2329
 
<dd><p>The option for <a class="reference internal" href="#os.waitpid" title="os.waitpid"><code class="xref py py-func docutils literal"><span class="pre">waitpid()</span></code></a> to return immediately if no child process status
2330
 
is available immediately. The function returns <code class="docutils literal"><span class="pre">(0,</span> <span class="pre">0)</span></code> in this case.</p>
2331
 
<p>Availability: Unix.</p>
2332
 
</dd></dl>
2333
 
 
2334
 
<dl class="data">
2335
 
<dt id="os.WCONTINUED">
2336
 
<code class="descclassname">os.</code><code class="descname">WCONTINUED</code><a class="headerlink" href="#os.WCONTINUED" title="Permalink to this definition">¶</a></dt>
2337
 
<dd><p>This option causes child processes to be reported if they have been continued
2338
 
from a job control stop since their status was last reported.</p>
2339
 
<p>Availability: Some Unix systems.</p>
2340
 
<div class="versionadded">
2341
 
<p><span class="versionmodified">New in version 2.3.</span></p>
2342
 
</div>
2343
 
</dd></dl>
2344
 
 
2345
 
<dl class="data">
2346
 
<dt id="os.WUNTRACED">
2347
 
<code class="descclassname">os.</code><code class="descname">WUNTRACED</code><a class="headerlink" href="#os.WUNTRACED" title="Permalink to this definition">¶</a></dt>
2348
 
<dd><p>This option causes child processes to be reported if they have been stopped but
2349
 
their current state has not been reported since they were stopped.</p>
2350
 
<p>Availability: Unix.</p>
2351
 
<div class="versionadded">
2352
 
<p><span class="versionmodified">New in version 2.3.</span></p>
2353
 
</div>
2354
 
</dd></dl>
2355
 
 
2356
 
<p>The following functions take a process status code as returned by
2357
 
<a class="reference internal" href="#os.system" title="os.system"><code class="xref py py-func docutils literal"><span class="pre">system()</span></code></a>, <a class="reference internal" href="#os.wait" title="os.wait"><code class="xref py py-func docutils literal"><span class="pre">wait()</span></code></a>, or <a class="reference internal" href="#os.waitpid" title="os.waitpid"><code class="xref py py-func docutils literal"><span class="pre">waitpid()</span></code></a> as a parameter.  They may be
2358
 
used to determine the disposition of a process.</p>
2359
 
<dl class="function">
2360
 
<dt id="os.WCOREDUMP">
2361
 
<code class="descclassname">os.</code><code class="descname">WCOREDUMP</code><span class="sig-paren">(</span><em>status</em><span class="sig-paren">)</span><a class="headerlink" href="#os.WCOREDUMP" title="Permalink to this definition">¶</a></dt>
2362
 
<dd><p>Return <code class="docutils literal"><span class="pre">True</span></code> if a core dump was generated for the process, otherwise
2363
 
return <code class="docutils literal"><span class="pre">False</span></code>.</p>
2364
 
<p>Availability: Unix.</p>
2365
 
<div class="versionadded">
2366
 
<p><span class="versionmodified">New in version 2.3.</span></p>
2367
 
</div>
2368
 
</dd></dl>
2369
 
 
2370
 
<dl class="function">
2371
 
<dt id="os.WIFCONTINUED">
2372
 
<code class="descclassname">os.</code><code class="descname">WIFCONTINUED</code><span class="sig-paren">(</span><em>status</em><span class="sig-paren">)</span><a class="headerlink" href="#os.WIFCONTINUED" title="Permalink to this definition">¶</a></dt>
2373
 
<dd><p>Return <code class="docutils literal"><span class="pre">True</span></code> if the process has been continued from a job control stop,
2374
 
otherwise return <code class="docutils literal"><span class="pre">False</span></code>.</p>
2375
 
<p>Availability: Unix.</p>
2376
 
<div class="versionadded">
2377
 
<p><span class="versionmodified">New in version 2.3.</span></p>
2378
 
</div>
2379
 
</dd></dl>
2380
 
 
2381
 
<dl class="function">
2382
 
<dt id="os.WIFSTOPPED">
2383
 
<code class="descclassname">os.</code><code class="descname">WIFSTOPPED</code><span class="sig-paren">(</span><em>status</em><span class="sig-paren">)</span><a class="headerlink" href="#os.WIFSTOPPED" title="Permalink to this definition">¶</a></dt>
2384
 
<dd><p>Return <code class="docutils literal"><span class="pre">True</span></code> if the process has been stopped, otherwise return
2385
 
<code class="docutils literal"><span class="pre">False</span></code>.</p>
2386
 
<p>Availability: Unix.</p>
2387
 
</dd></dl>
2388
 
 
2389
 
<dl class="function">
2390
 
<dt id="os.WIFSIGNALED">
2391
 
<code class="descclassname">os.</code><code class="descname">WIFSIGNALED</code><span class="sig-paren">(</span><em>status</em><span class="sig-paren">)</span><a class="headerlink" href="#os.WIFSIGNALED" title="Permalink to this definition">¶</a></dt>
2392
 
<dd><p>Return <code class="docutils literal"><span class="pre">True</span></code> if the process exited due to a signal, otherwise return
2393
 
<code class="docutils literal"><span class="pre">False</span></code>.</p>
2394
 
<p>Availability: Unix.</p>
2395
 
</dd></dl>
2396
 
 
2397
 
<dl class="function">
2398
 
<dt id="os.WIFEXITED">
2399
 
<code class="descclassname">os.</code><code class="descname">WIFEXITED</code><span class="sig-paren">(</span><em>status</em><span class="sig-paren">)</span><a class="headerlink" href="#os.WIFEXITED" title="Permalink to this definition">¶</a></dt>
2400
 
<dd><p>Return <code class="docutils literal"><span class="pre">True</span></code> if the process exited using the <em class="manpage">exit(2)</em> system call,
2401
 
otherwise return <code class="docutils literal"><span class="pre">False</span></code>.</p>
2402
 
<p>Availability: Unix.</p>
2403
 
</dd></dl>
2404
 
 
2405
 
<dl class="function">
2406
 
<dt id="os.WEXITSTATUS">
2407
 
<code class="descclassname">os.</code><code class="descname">WEXITSTATUS</code><span class="sig-paren">(</span><em>status</em><span class="sig-paren">)</span><a class="headerlink" href="#os.WEXITSTATUS" title="Permalink to this definition">¶</a></dt>
2408
 
<dd><p>If <code class="docutils literal"><span class="pre">WIFEXITED(status)</span></code> is true, return the integer parameter to the
2409
 
<em class="manpage">exit(2)</em> system call.  Otherwise, the return value is meaningless.</p>
2410
 
<p>Availability: Unix.</p>
2411
 
</dd></dl>
2412
 
 
2413
 
<dl class="function">
2414
 
<dt id="os.WSTOPSIG">
2415
 
<code class="descclassname">os.</code><code class="descname">WSTOPSIG</code><span class="sig-paren">(</span><em>status</em><span class="sig-paren">)</span><a class="headerlink" href="#os.WSTOPSIG" title="Permalink to this definition">¶</a></dt>
2416
 
<dd><p>Return the signal which caused the process to stop.</p>
2417
 
<p>Availability: Unix.</p>
2418
 
</dd></dl>
2419
 
 
2420
 
<dl class="function">
2421
 
<dt id="os.WTERMSIG">
2422
 
<code class="descclassname">os.</code><code class="descname">WTERMSIG</code><span class="sig-paren">(</span><em>status</em><span class="sig-paren">)</span><a class="headerlink" href="#os.WTERMSIG" title="Permalink to this definition">¶</a></dt>
2423
 
<dd><p>Return the signal which caused the process to exit.</p>
2424
 
<p>Availability: Unix.</p>
2425
 
</dd></dl>
2426
 
 
2427
 
</div>
2428
 
<div class="section" id="miscellaneous-system-information">
2429
 
<span id="os-path"></span><h2>15.1.6. Miscellaneous System Information<a class="headerlink" href="#miscellaneous-system-information" title="Permalink to this headline">¶</a></h2>
2430
 
<dl class="function">
2431
 
<dt id="os.confstr">
2432
 
<code class="descclassname">os.</code><code class="descname">confstr</code><span class="sig-paren">(</span><em>name</em><span class="sig-paren">)</span><a class="headerlink" href="#os.confstr" title="Permalink to this definition">¶</a></dt>
2433
 
<dd><p>Return string-valued system configuration values. <em>name</em> specifies the
2434
 
configuration value to retrieve; it may be a string which is the name of a
2435
 
defined system value; these names are specified in a number of standards (POSIX,
2436
 
Unix 95, Unix 98, and others).  Some platforms define additional names as well.
2437
 
The names known to the host operating system are given as the keys of the
2438
 
<code class="docutils literal"><span class="pre">confstr_names</span></code> dictionary.  For configuration variables not included in that
2439
 
mapping, passing an integer for <em>name</em> is also accepted.</p>
2440
 
<p>If the configuration value specified by <em>name</em> isn&#8217;t defined, <code class="docutils literal"><span class="pre">None</span></code> is
2441
 
returned.</p>
2442
 
<p>If <em>name</em> is a string and is not known, <a class="reference internal" href="exceptions.html#exceptions.ValueError" title="exceptions.ValueError"><code class="xref py py-exc docutils literal"><span class="pre">ValueError</span></code></a> is raised.  If a
2443
 
specific value for <em>name</em> is not supported by the host system, even if it is
2444
 
included in <code class="docutils literal"><span class="pre">confstr_names</span></code>, an <a class="reference internal" href="exceptions.html#exceptions.OSError" title="exceptions.OSError"><code class="xref py py-exc docutils literal"><span class="pre">OSError</span></code></a> is raised with
2445
 
<a class="reference internal" href="errno.html#errno.EINVAL" title="errno.EINVAL"><code class="xref py py-const docutils literal"><span class="pre">errno.EINVAL</span></code></a> for the error number.</p>
2446
 
<p>Availability: Unix</p>
2447
 
</dd></dl>
2448
 
 
2449
 
<dl class="data">
2450
 
<dt id="os.confstr_names">
2451
 
<code class="descclassname">os.</code><code class="descname">confstr_names</code><a class="headerlink" href="#os.confstr_names" title="Permalink to this definition">¶</a></dt>
2452
 
<dd><p>Dictionary mapping names accepted by <a class="reference internal" href="#os.confstr" title="os.confstr"><code class="xref py py-func docutils literal"><span class="pre">confstr()</span></code></a> to the integer values
2453
 
defined for those names by the host operating system. This can be used to
2454
 
determine the set of names known to the system.</p>
2455
 
<p>Availability: Unix.</p>
2456
 
</dd></dl>
2457
 
 
2458
 
<dl class="function">
2459
 
<dt id="os.getloadavg">
2460
 
<code class="descclassname">os.</code><code class="descname">getloadavg</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.getloadavg" title="Permalink to this definition">¶</a></dt>
2461
 
<dd><p>Return the number of processes in the system run queue averaged over the last
2462
 
1, 5, and 15 minutes or raises <a class="reference internal" href="exceptions.html#exceptions.OSError" title="exceptions.OSError"><code class="xref py py-exc docutils literal"><span class="pre">OSError</span></code></a> if the load average was
2463
 
unobtainable.</p>
2464
 
<p>Availability: Unix.</p>
2465
 
<div class="versionadded">
2466
 
<p><span class="versionmodified">New in version 2.3.</span></p>
2467
 
</div>
2468
 
</dd></dl>
2469
 
 
2470
 
<dl class="function">
2471
 
<dt id="os.sysconf">
2472
 
<code class="descclassname">os.</code><code class="descname">sysconf</code><span class="sig-paren">(</span><em>name</em><span class="sig-paren">)</span><a class="headerlink" href="#os.sysconf" title="Permalink to this definition">¶</a></dt>
2473
 
<dd><p>Return integer-valued system configuration values. If the configuration value
2474
 
specified by <em>name</em> isn&#8217;t defined, <code class="docutils literal"><span class="pre">-1</span></code> is returned.  The comments regarding
2475
 
the <em>name</em> parameter for <a class="reference internal" href="#os.confstr" title="os.confstr"><code class="xref py py-func docutils literal"><span class="pre">confstr()</span></code></a> apply here as well; the dictionary that
2476
 
provides information on the known names is given by <code class="docutils literal"><span class="pre">sysconf_names</span></code>.</p>
2477
 
<p>Availability: Unix.</p>
2478
 
</dd></dl>
2479
 
 
2480
 
<dl class="data">
2481
 
<dt id="os.sysconf_names">
2482
 
<code class="descclassname">os.</code><code class="descname">sysconf_names</code><a class="headerlink" href="#os.sysconf_names" title="Permalink to this definition">¶</a></dt>
2483
 
<dd><p>Dictionary mapping names accepted by <a class="reference internal" href="#os.sysconf" title="os.sysconf"><code class="xref py py-func docutils literal"><span class="pre">sysconf()</span></code></a> to the integer values
2484
 
defined for those names by the host operating system. This can be used to
2485
 
determine the set of names known to the system.</p>
2486
 
<p>Availability: Unix.</p>
2487
 
</dd></dl>
2488
 
 
2489
 
<p>The following data values are used to support path manipulation operations.  These
2490
 
are defined for all platforms.</p>
2491
 
<p>Higher-level operations on pathnames are defined in the <a class="reference internal" href="os.path.html#module-os.path" title="os.path: Operations on pathnames."><code class="xref py py-mod docutils literal"><span class="pre">os.path</span></code></a> module.</p>
2492
 
<dl class="data">
2493
 
<dt id="os.curdir">
2494
 
<code class="descclassname">os.</code><code class="descname">curdir</code><a class="headerlink" href="#os.curdir" title="Permalink to this definition">¶</a></dt>
2495
 
<dd><p>The constant string used by the operating system to refer to the current
2496
 
directory. This is <code class="docutils literal"><span class="pre">'.'</span></code> for Windows and POSIX. Also available via
2497
 
<a class="reference internal" href="os.path.html#module-os.path" title="os.path: Operations on pathnames."><code class="xref py py-mod docutils literal"><span class="pre">os.path</span></code></a>.</p>
2498
 
</dd></dl>
2499
 
 
2500
 
<dl class="data">
2501
 
<dt id="os.pardir">
2502
 
<code class="descclassname">os.</code><code class="descname">pardir</code><a class="headerlink" href="#os.pardir" title="Permalink to this definition">¶</a></dt>
2503
 
<dd><p>The constant string used by the operating system to refer to the parent
2504
 
directory. This is <code class="docutils literal"><span class="pre">'..'</span></code> for Windows and POSIX. Also available via
2505
 
<a class="reference internal" href="os.path.html#module-os.path" title="os.path: Operations on pathnames."><code class="xref py py-mod docutils literal"><span class="pre">os.path</span></code></a>.</p>
2506
 
</dd></dl>
2507
 
 
2508
 
<dl class="data">
2509
 
<dt id="os.sep">
2510
 
<code class="descclassname">os.</code><code class="descname">sep</code><a class="headerlink" href="#os.sep" title="Permalink to this definition">¶</a></dt>
2511
 
<dd><p>The character used by the operating system to separate pathname components.
2512
 
This is <code class="docutils literal"><span class="pre">'/'</span></code> for POSIX and <code class="docutils literal"><span class="pre">'\\'</span></code> for Windows.  Note that knowing this
2513
 
is not sufficient to be able to parse or concatenate pathnames &#8212; use
2514
 
<a class="reference internal" href="os.path.html#os.path.split" title="os.path.split"><code class="xref py py-func docutils literal"><span class="pre">os.path.split()</span></code></a> and <a class="reference internal" href="os.path.html#os.path.join" title="os.path.join"><code class="xref py py-func docutils literal"><span class="pre">os.path.join()</span></code></a> &#8212; but it is occasionally
2515
 
useful. Also available via <a class="reference internal" href="os.path.html#module-os.path" title="os.path: Operations on pathnames."><code class="xref py py-mod docutils literal"><span class="pre">os.path</span></code></a>.</p>
2516
 
</dd></dl>
2517
 
 
2518
 
<dl class="data">
2519
 
<dt id="os.altsep">
2520
 
<code class="descclassname">os.</code><code class="descname">altsep</code><a class="headerlink" href="#os.altsep" title="Permalink to this definition">¶</a></dt>
2521
 
<dd><p>An alternative character used by the operating system to separate pathname
2522
 
components, or <code class="docutils literal"><span class="pre">None</span></code> if only one separator character exists.  This is set to
2523
 
<code class="docutils literal"><span class="pre">'/'</span></code> on Windows systems where <code class="docutils literal"><span class="pre">sep</span></code> is a backslash. Also available via
2524
 
<a class="reference internal" href="os.path.html#module-os.path" title="os.path: Operations on pathnames."><code class="xref py py-mod docutils literal"><span class="pre">os.path</span></code></a>.</p>
2525
 
</dd></dl>
2526
 
 
2527
 
<dl class="data">
2528
 
<dt id="os.extsep">
2529
 
<code class="descclassname">os.</code><code class="descname">extsep</code><a class="headerlink" href="#os.extsep" title="Permalink to this definition">¶</a></dt>
2530
 
<dd><p>The character which separates the base filename from the extension; for example,
2531
 
the <code class="docutils literal"><span class="pre">'.'</span></code> in <code class="file docutils literal"><span class="pre">os.py</span></code>. Also available via <a class="reference internal" href="os.path.html#module-os.path" title="os.path: Operations on pathnames."><code class="xref py py-mod docutils literal"><span class="pre">os.path</span></code></a>.</p>
2532
 
<div class="versionadded">
2533
 
<p><span class="versionmodified">New in version 2.2.</span></p>
2534
 
</div>
2535
 
</dd></dl>
2536
 
 
2537
 
<dl class="data">
2538
 
<dt id="os.pathsep">
2539
 
<code class="descclassname">os.</code><code class="descname">pathsep</code><a class="headerlink" href="#os.pathsep" title="Permalink to this definition">¶</a></dt>
2540
 
<dd><p>The character conventionally used by the operating system to separate search
2541
 
path components (as in <span class="target" id="index-30"></span><code class="xref std std-envvar docutils literal"><span class="pre">PATH</span></code>), such as <code class="docutils literal"><span class="pre">':'</span></code> for POSIX or <code class="docutils literal"><span class="pre">';'</span></code> for
2542
 
Windows. Also available via <a class="reference internal" href="os.path.html#module-os.path" title="os.path: Operations on pathnames."><code class="xref py py-mod docutils literal"><span class="pre">os.path</span></code></a>.</p>
2543
 
</dd></dl>
2544
 
 
2545
 
<dl class="data">
2546
 
<dt id="os.defpath">
2547
 
<code class="descclassname">os.</code><code class="descname">defpath</code><a class="headerlink" href="#os.defpath" title="Permalink to this definition">¶</a></dt>
2548
 
<dd><p>The default search path used by <a class="reference internal" href="#os.execl" title="os.execl"><code class="xref py py-func docutils literal"><span class="pre">exec*p*</span></code></a> and
2549
 
<a class="reference internal" href="#os.spawnl" title="os.spawnl"><code class="xref py py-func docutils literal"><span class="pre">spawn*p*</span></code></a> if the environment doesn&#8217;t have a <code class="docutils literal"><span class="pre">'PATH'</span></code>
2550
 
key. Also available via <a class="reference internal" href="os.path.html#module-os.path" title="os.path: Operations on pathnames."><code class="xref py py-mod docutils literal"><span class="pre">os.path</span></code></a>.</p>
2551
 
</dd></dl>
2552
 
 
2553
 
<dl class="data">
2554
 
<dt id="os.linesep">
2555
 
<code class="descclassname">os.</code><code class="descname">linesep</code><a class="headerlink" href="#os.linesep" title="Permalink to this definition">¶</a></dt>
2556
 
<dd><p>The string used to separate (or, rather, terminate) lines on the current
2557
 
platform.  This may be a single character, such as <code class="docutils literal"><span class="pre">'\n'</span></code> for POSIX, or
2558
 
multiple characters, for example, <code class="docutils literal"><span class="pre">'\r\n'</span></code> for Windows. Do not use
2559
 
<em>os.linesep</em> as a line terminator when writing files opened in text mode (the
2560
 
default); use a single <code class="docutils literal"><span class="pre">'\n'</span></code> instead, on all platforms.</p>
2561
 
</dd></dl>
2562
 
 
2563
 
<dl class="data">
2564
 
<dt id="os.devnull">
2565
 
<code class="descclassname">os.</code><code class="descname">devnull</code><a class="headerlink" href="#os.devnull" title="Permalink to this definition">¶</a></dt>
2566
 
<dd><p>The file path of the null device. For example: <code class="docutils literal"><span class="pre">'/dev/null'</span></code> for
2567
 
POSIX, <code class="docutils literal"><span class="pre">'nul'</span></code> for Windows.  Also available via <a class="reference internal" href="os.path.html#module-os.path" title="os.path: Operations on pathnames."><code class="xref py py-mod docutils literal"><span class="pre">os.path</span></code></a>.</p>
2568
 
<div class="versionadded">
2569
 
<p><span class="versionmodified">New in version 2.4.</span></p>
2570
 
</div>
2571
 
</dd></dl>
2572
 
 
2573
 
</div>
2574
 
<div class="section" id="miscellaneous-functions">
2575
 
<span id="os-miscfunc"></span><h2>15.1.7. Miscellaneous Functions<a class="headerlink" href="#miscellaneous-functions" title="Permalink to this headline">¶</a></h2>
2576
 
<dl class="function">
2577
 
<dt id="os.urandom">
2578
 
<code class="descclassname">os.</code><code class="descname">urandom</code><span class="sig-paren">(</span><em>n</em><span class="sig-paren">)</span><a class="headerlink" href="#os.urandom" title="Permalink to this definition">¶</a></dt>
2579
 
<dd><p>Return a string of <em>n</em> random bytes suitable for cryptographic use.</p>
2580
 
<p>This function returns random bytes from an OS-specific randomness source.  The
2581
 
returned data should be unpredictable enough for cryptographic applications,
2582
 
though its exact quality depends on the OS implementation.  On a UNIX-like
2583
 
system this will query <code class="docutils literal"><span class="pre">/dev/urandom</span></code>, and on Windows it will use
2584
 
<code class="docutils literal"><span class="pre">CryptGenRandom()</span></code>.  If a randomness source is not found,
2585
 
<a class="reference internal" href="exceptions.html#exceptions.NotImplementedError" title="exceptions.NotImplementedError"><code class="xref py py-exc docutils literal"><span class="pre">NotImplementedError</span></code></a> will be raised.</p>
2586
 
<p>For an easy-to-use interface to the random number generator
2587
 
provided by your platform, please see <a class="reference internal" href="random.html#random.SystemRandom" title="random.SystemRandom"><code class="xref py py-class docutils literal"><span class="pre">random.SystemRandom</span></code></a>.</p>
2588
 
<div class="versionadded">
2589
 
<p><span class="versionmodified">New in version 2.4.</span></p>
2590
 
</div>
2591
 
</dd></dl>
2592
 
 
2593
 
</div>
2594
 
</div>
2595
 
 
2596
 
 
2597
 
          </div>
2598
 
        </div>
2599
 
      </div>
2600
 
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
2601
 
        <div class="sphinxsidebarwrapper">
2602
 
  <h3><a href="../contents.html">Table Of Contents</a></h3>
2603
 
  <ul>
2604
 
<li><a class="reference internal" href="#">15.1. <code class="docutils literal"><span class="pre">os</span></code> &#8212; Miscellaneous operating system interfaces</a><ul>
2605
 
<li><a class="reference internal" href="#process-parameters">15.1.1. Process Parameters</a></li>
2606
 
<li><a class="reference internal" href="#file-object-creation">15.1.2. File Object Creation</a></li>
2607
 
<li><a class="reference internal" href="#file-descriptor-operations">15.1.3. File Descriptor Operations</a><ul>
2608
 
<li><a class="reference internal" href="#open-flag-constants">15.1.3.1. <code class="docutils literal"><span class="pre">open()</span></code> flag constants</a></li>
2609
 
</ul>
2610
 
</li>
2611
 
<li><a class="reference internal" href="#files-and-directories">15.1.4. Files and Directories</a></li>
2612
 
<li><a class="reference internal" href="#process-management">15.1.5. Process Management</a></li>
2613
 
<li><a class="reference internal" href="#miscellaneous-system-information">15.1.6. Miscellaneous System Information</a></li>
2614
 
<li><a class="reference internal" href="#miscellaneous-functions">15.1.7. Miscellaneous Functions</a></li>
2615
 
</ul>
2616
 
</li>
2617
 
</ul>
2618
 
 
2619
 
  <h4>Previous topic</h4>
2620
 
  <p class="topless"><a href="allos.html"
2621
 
                        title="previous chapter">15. Generic Operating System Services</a></p>
2622
 
  <h4>Next topic</h4>
2623
 
  <p class="topless"><a href="io.html"
2624
 
                        title="next chapter">15.2. <code class="docutils literal"><span class="pre">io</span></code> &#8212; Core tools for working with streams</a></p>
2625
 
<h3>This Page</h3>
2626
 
<ul class="this-page-menu">
2627
 
  <li><a href="../bugs.html">Report a Bug</a></li>
2628
 
  <li><a href="../_sources/library/os.txt"
2629
 
         rel="nofollow">Show Source</a></li>
2630
 
</ul>
2631
 
 
2632
 
<div id="searchbox" style="display: none" role="search">
2633
 
  <h3>Quick search</h3>
2634
 
    <form class="search" action="../search.html" method="get">
2635
 
      <input type="text" name="q" />
2636
 
      <input type="submit" value="Go" />
2637
 
      <input type="hidden" name="check_keywords" value="yes" />
2638
 
      <input type="hidden" name="area" value="default" />
2639
 
    </form>
2640
 
    <p class="searchtip" style="font-size: 90%">
2641
 
    Enter search terms or a module, class or function name.
2642
 
    </p>
2643
 
</div>
2644
 
<script type="text/javascript">$('#searchbox').show(0);</script>
2645
 
        </div>
2646
 
      </div>
2647
 
      <div class="clearer"></div>
2648
 
    </div>  
2649
 
    <div class="related" role="navigation" aria-label="related navigation">
2650
 
      <h3>Navigation</h3>
2651
 
      <ul>
2652
 
        <li class="right" style="margin-right: 10px">
2653
 
          <a href="../genindex.html" title="General Index"
2654
 
             >index</a></li>
2655
 
        <li class="right" >
2656
 
          <a href="../py-modindex.html" title="Python Module Index"
2657
 
             >modules</a> |</li>
2658
 
        <li class="right" >
2659
 
          <a href="io.html" title="15.2. io — Core tools for working with streams"
2660
 
             >next</a> |</li>
2661
 
        <li class="right" >
2662
 
          <a href="allos.html" title="15. Generic Operating System Services"
2663
 
             >previous</a> |</li>
2664
 
        <li><img src="../_static/py.png" alt=""
2665
 
                 style="vertical-align: middle; margin-top: -1px"/></li>
2666
 
        <li><a href="https://www.python.org/">Python</a> &raquo;</li>
2667
 
        <li>
2668
 
          <span class="version_switcher_placeholder">2.7.11</span>
2669
 
          <a href="../index.html">Documentation</a> &raquo;
2670
 
        </li>
2671
 
 
2672
 
          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &raquo;</li>
2673
 
          <li class="nav-item nav-item-2"><a href="allos.html" >15. Generic Operating System Services</a> &raquo;</li> 
2674
 
      </ul>
2675
 
    </div>  
2676
 
    <div class="footer">
2677
 
    &copy; <a href="../copyright.html">Copyright</a> 1990-2016, Python Software Foundation.
2678
 
    <br />
2679
 
    The Python Software Foundation is a non-profit corporation.
2680
 
    <a href="https://www.python.org/psf/donations/">Please donate.</a>
2681
 
    <br />
2682
 
    Last updated on Jan 23, 2016.
2683
 
    <a href="../bugs.html">Found a bug</a>?
2684
 
    <br />
2685
 
    Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.3.3.
2686
 
    </div>
2687
 
 
2688
 
  </body>
2689
 
</html>
 
 
b'\\ No newline at end of file'