Sophie

Sophie

distrib > Mandriva > 2010.1 > x86_64 > media > contrib-backports > by-pkgid > 3ba3bd1608c672ba2129b098a48e9e4d > files > 752

python3-docs-3.2.2-3mdv2010.2.noarch.rpm



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>15.1. os — Miscellaneous operating system interfaces &mdash; Python v3.2.2 documentation</title>
    <link rel="stylesheet" href="../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '3.2.2',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/sidebar.js"></script>
    <link rel="search" type="application/opensearchdescription+xml"
          title="Search within Python v3.2.2 documentation"
          href="../_static/opensearch.xml"/>
    <link rel="author" title="About these documents" href="../about.html" />
    <link rel="copyright" title="Copyright" href="../copyright.html" />
    <link rel="top" title="Python v3.2.2 documentation" href="../index.html" />
    <link rel="up" title="15. Generic Operating System Services" href="allos.html" />
    <link rel="next" title="15.2. io — Core tools for working with streams" href="io.html" />
    <link rel="prev" title="15. Generic Operating System Services" href="allos.html" />
    <link rel="shortcut icon" type="image/png" href="../_static/py.png" />
 

  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="io.html" title="15.2. io — Core tools for working with streams"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="allos.html" title="15. Generic Operating System Services"
             accesskey="P">previous</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="../index.html">Python v3.2.2 documentation</a> &raquo;</li>

          <li><a href="index.html" >The Python Standard Library</a> &raquo;</li>
          <li><a href="allos.html" accesskey="U">15. Generic Operating System Services</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="module-os">
<span id="os-miscellaneous-operating-system-interfaces"></span><h1>15.1. <a class="reference internal" href="#module-os" title="os: Miscellaneous operating system interfaces."><tt class="xref py py-mod docutils literal"><span class="pre">os</span></tt></a> &#8212; Miscellaneous operating system interfaces<a class="headerlink" href="#module-os" title="Permalink to this headline">¶</a></h1>
<p>This module provides a portable way of using operating system dependent
functionality.  If you just want to read or write a file see <a class="reference internal" href="functions.html#open" title="open"><tt class="xref py py-func docutils literal"><span class="pre">open()</span></tt></a>, if
you want to manipulate paths, see the <a class="reference internal" href="os.path.html#module-os.path" title="os.path: Operations on pathnames."><tt class="xref py py-mod docutils literal"><span class="pre">os.path</span></tt></a> module, and if you want to
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."><tt class="xref py py-mod docutils literal"><span class="pre">fileinput</span></tt></a>
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."><tt class="xref py py-mod docutils literal"><span class="pre">tempfile</span></tt></a>
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."><tt class="xref py py-mod docutils literal"><span class="pre">shutil</span></tt></a>
module.</p>
<p>Notes on the availability of these functions:</p>
<ul class="simple">
<li>The design of all built-in operating system dependent modules of Python is
such that as long as the same functionality is available, it uses the same
interface; for example, the function <tt class="docutils literal"><span class="pre">os.stat(path)</span></tt> returns stat
information about <em>path</em> in the same format (which happens to have originated
with the POSIX interface).</li>
<li>Extensions peculiar to a particular operating system are also available
through the <a class="reference internal" href="#module-os" title="os: Miscellaneous operating system interfaces."><tt class="xref py py-mod docutils literal"><span class="pre">os</span></tt></a> module, but using them is of course a threat to
portability.</li>
<li>All functions accepting path or file names accept both bytes and string
objects, and result in an object of the same type, if a path or file name is
returned.</li>
<li>An &#8220;Availability: Unix&#8221; note means that this function is commonly found on
Unix systems.  It does not make any claims about its existence on a specific
operating system.</li>
<li>If not separately noted, all functions that claim &#8220;Availability: Unix&#8221; are
supported on Mac OS X, which builds on a Unix core.</li>
</ul>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">All functions in this module raise <a class="reference internal" href="exceptions.html#OSError" title="OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a> in the case of invalid or
inaccessible file names and paths, or other arguments that have the correct
type, but are not accepted by the operating system.</p>
</div>
<dl class="exception">
<dt id="os.error">
<em class="property">exception </em><tt class="descclassname">os.</tt><tt class="descname">error</tt><a class="headerlink" href="#os.error" title="Permalink to this definition">¶</a></dt>
<dd><p>An alias for the built-in <a class="reference internal" href="exceptions.html#OSError" title="OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a> exception.</p>
</dd></dl>

<dl class="data">
<dt id="os.name">
<tt class="descclassname">os.</tt><tt class="descname">name</tt><a class="headerlink" href="#os.name" title="Permalink to this definition">¶</a></dt>
<dd><p>The name of the operating system dependent module imported.  The following
names have currently been registered: <tt class="docutils literal"><span class="pre">'posix'</span></tt>, <tt class="docutils literal"><span class="pre">'nt'</span></tt>, <tt class="docutils literal"><span class="pre">'mac'</span></tt>,
<tt class="docutils literal"><span class="pre">'os2'</span></tt>, <tt class="docutils literal"><span class="pre">'ce'</span></tt>, <tt class="docutils literal"><span class="pre">'java'</span></tt>.</p>
<div class="admonition-see-also admonition seealso">
<p class="first admonition-title">See also</p>
<p><a class="reference internal" href="sys.html#sys.platform" title="sys.platform"><tt class="xref py py-attr docutils literal"><span class="pre">sys.platform</span></tt></a> has a finer granularity.  <a class="reference internal" href="#os.uname" title="os.uname"><tt class="xref py py-func docutils literal"><span class="pre">os.uname()</span></tt></a> gives
system-dependent version information.</p>
<p class="last">The <a class="reference internal" href="platform.html#module-platform" title="platform: Retrieves as much platform identifying data as possible."><tt class="xref py py-mod docutils literal"><span class="pre">platform</span></tt></a> module provides detailed checks for the
system&#8217;s identity.</p>
</div>
</dd></dl>

<div class="section" id="file-names-command-line-arguments-and-environment-variables">
<span id="os-filenames"></span><h2>15.1.1. File Names, Command Line Arguments, and Environment Variables<a class="headerlink" href="#file-names-command-line-arguments-and-environment-variables" title="Permalink to this headline">¶</a></h2>
<p>In Python, file names, command line arguments, and environment variables are
represented using the string type. On some systems, decoding these strings to
and from bytes is necessary before passing them to the operating system. Python
uses the file system encoding to perform this conversion (see
<a class="reference internal" href="sys.html#sys.getfilesystemencoding" title="sys.getfilesystemencoding"><tt class="xref py py-func docutils literal"><span class="pre">sys.getfilesystemencoding()</span></tt></a>).</p>
<p class="versionchanged">
<span class="versionmodified">Changed in version 3.1: </span>On some systems, conversion using the file system encoding may fail. In this
case, Python uses the <tt class="docutils literal"><span class="pre">surrogateescape</span></tt> encoding error handler, which means
that undecodable bytes are replaced by a Unicode character U+DCxx on
decoding, and these are again translated to the original byte on encoding.</p>
<p>The file system encoding must guarantee to successfully decode all bytes
below 128. If the file system encoding fails to provide this guarantee, API
functions may raise UnicodeErrors.</p>
</div>
<div class="section" id="process-parameters">
<span id="os-procinfo"></span><h2>15.1.2. Process Parameters<a class="headerlink" href="#process-parameters" title="Permalink to this headline">¶</a></h2>
<p>These functions and data items provide information and operate on the current
process and user.</p>
<dl class="data">
<dt id="os.environ">
<tt class="descclassname">os.</tt><tt class="descname">environ</tt><a class="headerlink" href="#os.environ" title="Permalink to this definition">¶</a></dt>
<dd><p>A mapping object representing the string environment. For example,
<tt class="docutils literal"><span class="pre">environ['HOME']</span></tt> is the pathname of your home directory (on some platforms),
and is equivalent to <tt class="docutils literal"><span class="pre">getenv(&quot;HOME&quot;)</span></tt> in C.</p>
<p>This mapping is captured the first time the <a class="reference internal" href="#module-os" title="os: Miscellaneous operating system interfaces."><tt class="xref py py-mod docutils literal"><span class="pre">os</span></tt></a> module is imported,
typically during Python startup as part of processing <tt class="file docutils literal"><span class="pre">site.py</span></tt>.  Changes
to the environment made after this time are not reflected in <tt class="docutils literal"><span class="pre">os.environ</span></tt>,
except for changes made by modifying <tt class="docutils literal"><span class="pre">os.environ</span></tt> directly.</p>
<p>If the platform supports the <a class="reference internal" href="#os.putenv" title="os.putenv"><tt class="xref py py-func docutils literal"><span class="pre">putenv()</span></tt></a> function, this mapping may be used
to modify the environment as well as query the environment.  <a class="reference internal" href="#os.putenv" title="os.putenv"><tt class="xref py py-func docutils literal"><span class="pre">putenv()</span></tt></a> will
be called automatically when the mapping is modified.</p>
<p>On Unix, keys and values use <a class="reference internal" href="sys.html#sys.getfilesystemencoding" title="sys.getfilesystemencoding"><tt class="xref py py-func docutils literal"><span class="pre">sys.getfilesystemencoding()</span></tt></a> and
<tt class="docutils literal"><span class="pre">'surrogateescape'</span></tt> error handler. Use <a class="reference internal" href="#os.environb" title="os.environb"><tt class="xref py py-data docutils literal"><span class="pre">environb</span></tt></a> if you would like
to use a different encoding.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Calling <a class="reference internal" href="#os.putenv" title="os.putenv"><tt class="xref py py-func docutils literal"><span class="pre">putenv()</span></tt></a> directly does not change <tt class="docutils literal"><span class="pre">os.environ</span></tt>, so it&#8217;s better
to modify <tt class="docutils literal"><span class="pre">os.environ</span></tt>.</p>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">On some platforms, including FreeBSD and Mac OS X, setting <tt class="docutils literal"><span class="pre">environ</span></tt> may
cause memory leaks.  Refer to the system documentation for
<tt class="xref c c-func docutils literal"><span class="pre">putenv()</span></tt>.</p>
</div>
<p>If <a class="reference internal" href="#os.putenv" title="os.putenv"><tt class="xref py py-func docutils literal"><span class="pre">putenv()</span></tt></a> is not provided, a modified copy of this mapping  may be
passed to the appropriate process-creation functions to cause  child processes
to use a modified environment.</p>
<p>If the platform supports the <a class="reference internal" href="#os.unsetenv" title="os.unsetenv"><tt class="xref py py-func docutils literal"><span class="pre">unsetenv()</span></tt></a> function, you can delete items in
this mapping to unset environment variables. <a class="reference internal" href="#os.unsetenv" title="os.unsetenv"><tt class="xref py py-func docutils literal"><span class="pre">unsetenv()</span></tt></a> will be called
automatically when an item is deleted from <tt class="docutils literal"><span class="pre">os.environ</span></tt>, and when
one of the <tt class="xref py py-meth docutils literal"><span class="pre">pop()</span></tt> or <tt class="xref py py-meth docutils literal"><span class="pre">clear()</span></tt> methods is called.</p>
</dd></dl>

<dl class="data">
<dt id="os.environb">
<tt class="descclassname">os.</tt><tt class="descname">environb</tt><a class="headerlink" href="#os.environb" title="Permalink to this definition">¶</a></dt>
<dd><p>Bytes version of <a class="reference internal" href="#os.environ" title="os.environ"><tt class="xref py py-data docutils literal"><span class="pre">environ</span></tt></a>: a mapping object representing the
environment as byte strings. <a class="reference internal" href="#os.environ" title="os.environ"><tt class="xref py py-data docutils literal"><span class="pre">environ</span></tt></a> and <a class="reference internal" href="#os.environb" title="os.environb"><tt class="xref py py-data docutils literal"><span class="pre">environb</span></tt></a> are
synchronized (modify <a class="reference internal" href="#os.environb" title="os.environb"><tt class="xref py py-data docutils literal"><span class="pre">environb</span></tt></a> updates <a class="reference internal" href="#os.environ" title="os.environ"><tt class="xref py py-data docutils literal"><span class="pre">environ</span></tt></a>, and vice
versa).</p>
<p><a class="reference internal" href="#os.environb" title="os.environb"><tt class="xref py py-data docutils literal"><span class="pre">environb</span></tt></a> is only available if <a class="reference internal" href="#os.supports_bytes_environ" title="os.supports_bytes_environ"><tt class="xref py py-data docutils literal"><span class="pre">supports_bytes_environ</span></tt></a> is
True.</p>
<p class="versionadded">
<span class="versionmodified">New in version 3.2.</span></p>
</dd></dl>

<dl class="function">
<dt>
<tt class="descclassname">os.</tt><tt class="descname">chdir</tt><big>(</big><em>path</em><big>)</big></dt>
<dt>
<tt class="descclassname">os.</tt><tt class="descname">fchdir</tt><big>(</big><em>fd</em><big>)</big></dt>
<dt>
<tt class="descclassname">os.</tt><tt class="descname">getcwd</tt><big>(</big><big>)</big></dt>
<dd><p>These functions are described in <a class="reference internal" href="#os-file-dir"><em>Files and Directories</em></a>.</p>
</dd></dl>

<dl class="function">
<dt id="os.fsencode">
<tt class="descclassname">os.</tt><tt class="descname">fsencode</tt><big>(</big><em>filename</em><big>)</big><a class="headerlink" href="#os.fsencode" title="Permalink to this definition">¶</a></dt>
<dd><p>Encode <em>filename</em> to the filesystem encoding with <tt class="docutils literal"><span class="pre">'surrogateescape'</span></tt>
error handler, or <tt class="docutils literal"><span class="pre">'strict'</span></tt> on Windows; return <a class="reference internal" href="functions.html#bytes" title="bytes"><tt class="xref py py-class docutils literal"><span class="pre">bytes</span></tt></a> unchanged.</p>
<p><a class="reference internal" href="#os.fsdecode" title="os.fsdecode"><tt class="xref py py-func docutils literal"><span class="pre">fsdecode()</span></tt></a> is the reverse function.</p>
<p class="versionadded">
<span class="versionmodified">New in version 3.2.</span></p>
</dd></dl>

<dl class="function">
<dt id="os.fsdecode">
<tt class="descclassname">os.</tt><tt class="descname">fsdecode</tt><big>(</big><em>filename</em><big>)</big><a class="headerlink" href="#os.fsdecode" title="Permalink to this definition">¶</a></dt>
<dd><p>Decode <em>filename</em> from the filesystem encoding with <tt class="docutils literal"><span class="pre">'surrogateescape'</span></tt>
error handler, or <tt class="docutils literal"><span class="pre">'strict'</span></tt> on Windows; return <a class="reference internal" href="functions.html#str" title="str"><tt class="xref py py-class docutils literal"><span class="pre">str</span></tt></a> unchanged.</p>
<p><a class="reference internal" href="#os.fsencode" title="os.fsencode"><tt class="xref py py-func docutils literal"><span class="pre">fsencode()</span></tt></a> is the reverse function.</p>
<p class="versionadded">
<span class="versionmodified">New in version 3.2.</span></p>
</dd></dl>

<dl class="function">
<dt id="os.get_exec_path">
<tt class="descclassname">os.</tt><tt class="descname">get_exec_path</tt><big>(</big><em>env=None</em><big>)</big><a class="headerlink" href="#os.get_exec_path" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the list of directories that will be searched for a named
executable, similar to a shell, when launching a process.
<em>env</em>, when specified, should be an environment variable dictionary
to lookup the PATH in.
By default, when <em>env</em> is None, <a class="reference internal" href="#os.environ" title="os.environ"><tt class="xref py py-data docutils literal"><span class="pre">environ</span></tt></a> is used.</p>
<p class="versionadded">
<span class="versionmodified">New in version 3.2.</span></p>
</dd></dl>

<dl class="function">
<dt id="os.ctermid">
<tt class="descclassname">os.</tt><tt class="descname">ctermid</tt><big>(</big><big>)</big><a class="headerlink" href="#os.ctermid" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the filename corresponding to the controlling terminal of the process.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.getegid">
<tt class="descclassname">os.</tt><tt class="descname">getegid</tt><big>(</big><big>)</big><a class="headerlink" href="#os.getegid" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the effective group id of the current process.  This corresponds to the
&#8220;set id&#8221; bit on the file being executed in the current process.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.geteuid">
<tt class="descclassname">os.</tt><tt class="descname">geteuid</tt><big>(</big><big>)</big><a class="headerlink" href="#os.geteuid" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-0">Return the current process&#8217;s effective user id.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.getgid">
<tt class="descclassname">os.</tt><tt class="descname">getgid</tt><big>(</big><big>)</big><a class="headerlink" href="#os.getgid" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-1">Return the real group id of the current process.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.getgroups">
<tt class="descclassname">os.</tt><tt class="descname">getgroups</tt><big>(</big><big>)</big><a class="headerlink" href="#os.getgroups" title="Permalink to this definition">¶</a></dt>
<dd><p>Return list of supplemental group ids associated with the current process.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.initgroups">
<tt class="descclassname">os.</tt><tt class="descname">initgroups</tt><big>(</big><em>username</em>, <em>gid</em><big>)</big><a class="headerlink" href="#os.initgroups" title="Permalink to this definition">¶</a></dt>
<dd><p>Call the system initgroups() to initialize the group access list with all of
the groups of which the specified username is a member, plus the specified
group id.</p>
<p>Availability: Unix.</p>
<p class="versionadded">
<span class="versionmodified">New in version 3.2.</span></p>
</dd></dl>

<dl class="function">
<dt id="os.getlogin">
<tt class="descclassname">os.</tt><tt class="descname">getlogin</tt><big>(</big><big>)</big><a class="headerlink" href="#os.getlogin" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the name of the user logged in on the controlling terminal of the
process.  For most purposes, it is more useful to use the environment variables
<span class="target" id="index-2"></span><tt class="xref std std-envvar docutils literal"><span class="pre">LOGNAME</span></tt> or <span class="target" id="index-3"></span><tt class="xref std std-envvar docutils literal"><span class="pre">USERNAME</span></tt> to find out who the user is, or
<tt class="docutils literal"><span class="pre">pwd.getpwuid(os.getuid())[0]</span></tt> to get the login name of the currently
effective user id.</p>
<p>Availability: Unix, Windows.</p>
</dd></dl>

<dl class="function">
<dt id="os.getpgid">
<tt class="descclassname">os.</tt><tt class="descname">getpgid</tt><big>(</big><em>pid</em><big>)</big><a class="headerlink" href="#os.getpgid" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the process group id of the process with process id <em>pid</em>. If <em>pid</em> is 0,
the process group id of the current process is returned.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.getpgrp">
<tt class="descclassname">os.</tt><tt class="descname">getpgrp</tt><big>(</big><big>)</big><a class="headerlink" href="#os.getpgrp" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-4">Return the id of the current process group.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.getpid">
<tt class="descclassname">os.</tt><tt class="descname">getpid</tt><big>(</big><big>)</big><a class="headerlink" href="#os.getpid" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-5">Return the current process id.</p>
<p>Availability: Unix, Windows.</p>
</dd></dl>

<dl class="function">
<dt id="os.getppid">
<tt class="descclassname">os.</tt><tt class="descname">getppid</tt><big>(</big><big>)</big><a class="headerlink" href="#os.getppid" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-6">Return the parent&#8217;s process id.  When the parent process has exited, on Unix
the id returned is the one of the init process (1), on Windows it is still
the same id, which may be already reused by another process.</p>
<p>Availability: Unix, Windows</p>
<p class="versionchanged">
<span class="versionmodified">Changed in version 3.2: </span>Added support for Windows.</p>
</dd></dl>

<dl class="function">
<dt id="os.getresuid">
<tt class="descclassname">os.</tt><tt class="descname">getresuid</tt><big>(</big><big>)</big><a class="headerlink" href="#os.getresuid" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a tuple (ruid, euid, suid) denoting the current process&#8217;s
real, effective, and saved user ids.</p>
<p>Availability: Unix.</p>
<p class="versionadded">
<span class="versionmodified">New in version 3.2.</span></p>
</dd></dl>

<dl class="function">
<dt id="os.getresgid">
<tt class="descclassname">os.</tt><tt class="descname">getresgid</tt><big>(</big><big>)</big><a class="headerlink" href="#os.getresgid" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a tuple (rgid, egid, sgid) denoting the current process&#8217;s
real, effective, and saved group ids.</p>
<p>Availability: Unix.</p>
<p class="versionadded">
<span class="versionmodified">New in version 3.2.</span></p>
</dd></dl>

<dl class="function">
<dt id="os.getuid">
<tt class="descclassname">os.</tt><tt class="descname">getuid</tt><big>(</big><big>)</big><a class="headerlink" href="#os.getuid" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-7">Return the current process&#8217;s user id.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.getenv">
<tt class="descclassname">os.</tt><tt class="descname">getenv</tt><big>(</big><em>key</em>, <em>default=None</em><big>)</big><a class="headerlink" href="#os.getenv" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the value of the environment variable <em>key</em> if it exists, or
<em>default</em> if it doesn&#8217;t. <em>key</em>, <em>default</em> and the result are str.</p>
<p>On Unix, keys and values are decoded with <a class="reference internal" href="sys.html#sys.getfilesystemencoding" title="sys.getfilesystemencoding"><tt class="xref py py-func docutils literal"><span class="pre">sys.getfilesystemencoding()</span></tt></a>
and <tt class="docutils literal"><span class="pre">'surrogateescape'</span></tt> error handler. Use <a class="reference internal" href="#os.getenvb" title="os.getenvb"><tt class="xref py py-func docutils literal"><span class="pre">os.getenvb()</span></tt></a> if you
would like to use a different encoding.</p>
<p>Availability: most flavors of Unix, Windows.</p>
</dd></dl>

<dl class="function">
<dt id="os.getenvb">
<tt class="descclassname">os.</tt><tt class="descname">getenvb</tt><big>(</big><em>key</em>, <em>default=None</em><big>)</big><a class="headerlink" href="#os.getenvb" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the value of the environment variable <em>key</em> if it exists, or
<em>default</em> if it doesn&#8217;t. <em>key</em>, <em>default</em> and the result are bytes.</p>
<p>Availability: most flavors of Unix.</p>
<p class="versionadded">
<span class="versionmodified">New in version 3.2.</span></p>
</dd></dl>

<dl class="function">
<dt id="os.putenv">
<tt class="descclassname">os.</tt><tt class="descname">putenv</tt><big>(</big><em>key</em>, <em>value</em><big>)</big><a class="headerlink" href="#os.putenv" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-8">Set the environment variable named <em>key</em> to the string <em>value</em>.  Such
changes to the environment affect subprocesses started with <a class="reference internal" href="#os.system" title="os.system"><tt class="xref py py-func docutils literal"><span class="pre">os.system()</span></tt></a>,
<tt class="xref py py-func docutils literal"><span class="pre">popen()</span></tt> or <a class="reference internal" href="#os.fork" title="os.fork"><tt class="xref py py-func docutils literal"><span class="pre">fork()</span></tt></a> and <a class="reference internal" href="#os.execv" title="os.execv"><tt class="xref py py-func docutils literal"><span class="pre">execv()</span></tt></a>.</p>
<p>Availability: most flavors of Unix, Windows.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">On some platforms, including FreeBSD and Mac OS X, setting <tt class="docutils literal"><span class="pre">environ</span></tt> may
cause memory leaks. Refer to the system documentation for putenv.</p>
</div>
<p>When <a class="reference internal" href="#os.putenv" title="os.putenv"><tt class="xref py py-func docutils literal"><span class="pre">putenv()</span></tt></a> is supported, assignments to items in <tt class="docutils literal"><span class="pre">os.environ</span></tt> are
automatically translated into corresponding calls to <a class="reference internal" href="#os.putenv" title="os.putenv"><tt class="xref py py-func docutils literal"><span class="pre">putenv()</span></tt></a>; however,
calls to <a class="reference internal" href="#os.putenv" title="os.putenv"><tt class="xref py py-func docutils literal"><span class="pre">putenv()</span></tt></a> don&#8217;t update <tt class="docutils literal"><span class="pre">os.environ</span></tt>, so it is actually
preferable to assign to items of <tt class="docutils literal"><span class="pre">os.environ</span></tt>.</p>
</dd></dl>

<dl class="function">
<dt id="os.setegid">
<tt class="descclassname">os.</tt><tt class="descname">setegid</tt><big>(</big><em>egid</em><big>)</big><a class="headerlink" href="#os.setegid" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the current process&#8217;s effective group id.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.seteuid">
<tt class="descclassname">os.</tt><tt class="descname">seteuid</tt><big>(</big><em>euid</em><big>)</big><a class="headerlink" href="#os.seteuid" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the current process&#8217;s effective user id.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.setgid">
<tt class="descclassname">os.</tt><tt class="descname">setgid</tt><big>(</big><em>gid</em><big>)</big><a class="headerlink" href="#os.setgid" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the current process&#8217; group id.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.setgroups">
<tt class="descclassname">os.</tt><tt class="descname">setgroups</tt><big>(</big><em>groups</em><big>)</big><a class="headerlink" href="#os.setgroups" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the list of supplemental group ids associated with the current process to
<em>groups</em>. <em>groups</em> must be a sequence, and each element must be an integer
identifying a group. This operation is typically available only to the superuser.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.setpgrp">
<tt class="descclassname">os.</tt><tt class="descname">setpgrp</tt><big>(</big><big>)</big><a class="headerlink" href="#os.setpgrp" title="Permalink to this definition">¶</a></dt>
<dd><p>Call the system call <tt class="xref c c-func docutils literal"><span class="pre">setpgrp()</span></tt> or <tt class="xref c c-func docutils literal"><span class="pre">setpgrp(0,</span> <span class="pre">0)()</span></tt> depending on
which version is implemented (if any).  See the Unix manual for the semantics.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.setpgid">
<tt class="descclassname">os.</tt><tt class="descname">setpgid</tt><big>(</big><em>pid</em>, <em>pgrp</em><big>)</big><a class="headerlink" href="#os.setpgid" title="Permalink to this definition">¶</a></dt>
<dd><p>Call the system call <tt class="xref c c-func docutils literal"><span class="pre">setpgid()</span></tt> to set the process group id of the
process with id <em>pid</em> to the process group with id <em>pgrp</em>.  See the Unix manual
for the semantics.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.setregid">
<tt class="descclassname">os.</tt><tt class="descname">setregid</tt><big>(</big><em>rgid</em>, <em>egid</em><big>)</big><a class="headerlink" href="#os.setregid" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the current process&#8217;s real and effective group ids.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.setresgid">
<tt class="descclassname">os.</tt><tt class="descname">setresgid</tt><big>(</big><em>rgid</em>, <em>egid</em>, <em>sgid</em><big>)</big><a class="headerlink" href="#os.setresgid" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the current process&#8217;s real, effective, and saved group ids.</p>
<p>Availability: Unix.</p>
<p class="versionadded">
<span class="versionmodified">New in version 3.2.</span></p>
</dd></dl>

<dl class="function">
<dt id="os.setresuid">
<tt class="descclassname">os.</tt><tt class="descname">setresuid</tt><big>(</big><em>ruid</em>, <em>euid</em>, <em>suid</em><big>)</big><a class="headerlink" href="#os.setresuid" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the current process&#8217;s real, effective, and saved user ids.</p>
<p>Availability: Unix.</p>
<p class="versionadded">
<span class="versionmodified">New in version 3.2.</span></p>
</dd></dl>

<dl class="function">
<dt id="os.setreuid">
<tt class="descclassname">os.</tt><tt class="descname">setreuid</tt><big>(</big><em>ruid</em>, <em>euid</em><big>)</big><a class="headerlink" href="#os.setreuid" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the current process&#8217;s real and effective user ids.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.getsid">
<tt class="descclassname">os.</tt><tt class="descname">getsid</tt><big>(</big><em>pid</em><big>)</big><a class="headerlink" href="#os.getsid" title="Permalink to this definition">¶</a></dt>
<dd><p>Call the system call <tt class="xref c c-func docutils literal"><span class="pre">getsid()</span></tt>.  See the Unix manual for the semantics.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.setsid">
<tt class="descclassname">os.</tt><tt class="descname">setsid</tt><big>(</big><big>)</big><a class="headerlink" href="#os.setsid" title="Permalink to this definition">¶</a></dt>
<dd><p>Call the system call <tt class="xref c c-func docutils literal"><span class="pre">setsid()</span></tt>.  See the Unix manual for the semantics.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.setuid">
<tt class="descclassname">os.</tt><tt class="descname">setuid</tt><big>(</big><em>uid</em><big>)</big><a class="headerlink" href="#os.setuid" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-9">Set the current process&#8217;s user id.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.strerror">
<tt class="descclassname">os.</tt><tt class="descname">strerror</tt><big>(</big><em>code</em><big>)</big><a class="headerlink" href="#os.strerror" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the error message corresponding to the error code in <em>code</em>.
On platforms where <tt class="xref c c-func docutils literal"><span class="pre">strerror()</span></tt> returns <tt class="docutils literal"><span class="pre">NULL</span></tt> when given an unknown
error number, <a class="reference internal" href="exceptions.html#ValueError" title="ValueError"><tt class="xref py py-exc docutils literal"><span class="pre">ValueError</span></tt></a> is raised.</p>
<p>Availability: Unix, Windows.</p>
</dd></dl>

<dl class="data">
<dt id="os.supports_bytes_environ">
<tt class="descclassname">os.</tt><tt class="descname">supports_bytes_environ</tt><a class="headerlink" href="#os.supports_bytes_environ" title="Permalink to this definition">¶</a></dt>
<dd><p>True if the native OS type of the environment is bytes (eg. False on
Windows).</p>
<p class="versionadded">
<span class="versionmodified">New in version 3.2.</span></p>
</dd></dl>

<dl class="function">
<dt id="os.umask">
<tt class="descclassname">os.</tt><tt class="descname">umask</tt><big>(</big><em>mask</em><big>)</big><a class="headerlink" href="#os.umask" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the current numeric umask and return the previous umask.</p>
<p>Availability: Unix, Windows.</p>
</dd></dl>

<dl class="function">
<dt id="os.uname">
<tt class="descclassname">os.</tt><tt class="descname">uname</tt><big>(</big><big>)</big><a class="headerlink" href="#os.uname" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-10">Return a 5-tuple containing information identifying the current operating
system.  The tuple contains 5 strings: <tt class="docutils literal"><span class="pre">(sysname,</span> <span class="pre">nodename,</span> <span class="pre">release,</span> <span class="pre">version,</span>
<span class="pre">machine)</span></tt>.  Some systems truncate the nodename to 8 characters or to the
leading component; a better way to get the hostname is
<a class="reference internal" href="socket.html#socket.gethostname" title="socket.gethostname"><tt class="xref py py-func docutils literal"><span class="pre">socket.gethostname()</span></tt></a>  or even
<tt class="docutils literal"><span class="pre">socket.gethostbyaddr(socket.gethostname())</span></tt>.</p>
<p>Availability: recent flavors of Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.unsetenv">
<tt class="descclassname">os.</tt><tt class="descname">unsetenv</tt><big>(</big><em>key</em><big>)</big><a class="headerlink" href="#os.unsetenv" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-11">Unset (delete) the environment variable named <em>key</em>. Such changes to the
environment affect subprocesses started with <a class="reference internal" href="#os.system" title="os.system"><tt class="xref py py-func docutils literal"><span class="pre">os.system()</span></tt></a>, <tt class="xref py py-func docutils literal"><span class="pre">popen()</span></tt> or
<a class="reference internal" href="#os.fork" title="os.fork"><tt class="xref py py-func docutils literal"><span class="pre">fork()</span></tt></a> and <a class="reference internal" href="#os.execv" title="os.execv"><tt class="xref py py-func docutils literal"><span class="pre">execv()</span></tt></a>.</p>
<p>When <a class="reference internal" href="#os.unsetenv" title="os.unsetenv"><tt class="xref py py-func docutils literal"><span class="pre">unsetenv()</span></tt></a> is supported, deletion of items in <tt class="docutils literal"><span class="pre">os.environ</span></tt> is
automatically translated into a corresponding call to <a class="reference internal" href="#os.unsetenv" title="os.unsetenv"><tt class="xref py py-func docutils literal"><span class="pre">unsetenv()</span></tt></a>; however,
calls to <a class="reference internal" href="#os.unsetenv" title="os.unsetenv"><tt class="xref py py-func docutils literal"><span class="pre">unsetenv()</span></tt></a> don&#8217;t update <tt class="docutils literal"><span class="pre">os.environ</span></tt>, so it is actually
preferable to delete items of <tt class="docutils literal"><span class="pre">os.environ</span></tt>.</p>
<p>Availability: most flavors of Unix, Windows.</p>
</dd></dl>

</div>
<div class="section" id="file-object-creation">
<span id="os-newstreams"></span><h2>15.1.3. File Object Creation<a class="headerlink" href="#file-object-creation" title="Permalink to this headline">¶</a></h2>
<p>These functions create new <a class="reference internal" href="../glossary.html#term-file-object"><em class="xref std std-term">file objects</em></a>. (See also <a class="reference internal" href="functions.html#open" title="open"><tt class="xref py py-func docutils literal"><span class="pre">open()</span></tt></a>.)</p>
<dl class="function">
<dt id="os.fdopen">
<tt class="descclassname">os.</tt><tt class="descname">fdopen</tt><big>(</big><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><big>)</big><a class="headerlink" href="#os.fdopen" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-12">Return an open file object connected to the file descriptor <em>fd</em>.  The <em>mode</em>
and <em>bufsize</em> arguments have the same meaning as the corresponding arguments to
the built-in <a class="reference internal" href="functions.html#open" title="open"><tt class="xref py py-func docutils literal"><span class="pre">open()</span></tt></a> function.</p>
<p>When specified, the <em>mode</em> argument must start with one of the letters
<tt class="docutils literal"><span class="pre">'r'</span></tt>, <tt class="docutils literal"><span class="pre">'w'</span></tt>, or <tt class="docutils literal"><span class="pre">'a'</span></tt>, otherwise a <a class="reference internal" href="exceptions.html#ValueError" title="ValueError"><tt class="xref py py-exc docutils literal"><span class="pre">ValueError</span></tt></a> is raised.</p>
<p>On Unix, when the <em>mode</em> argument starts with <tt class="docutils literal"><span class="pre">'a'</span></tt>, the <em>O_APPEND</em> flag is
set on the file descriptor (which the <tt class="xref c c-func docutils literal"><span class="pre">fdopen()</span></tt> implementation already
does on most platforms).</p>
<p>Availability: Unix, Windows.</p>
</dd></dl>

</div>
<div class="section" id="file-descriptor-operations">
<span id="os-fd-ops"></span><h2>15.1.4. File Descriptor Operations<a class="headerlink" href="#file-descriptor-operations" title="Permalink to this headline">¶</a></h2>
<p>These functions operate on I/O streams referenced using file descriptors.</p>
<p>File descriptors are small integers corresponding to a file that has been opened
by the current process.  For example, standard input is usually file descriptor
0, standard output is 1, and standard error is 2.  Further files opened by a
process will then be assigned 3, 4, 5, and so forth.  The name &#8220;file descriptor&#8221;
is slightly deceptive; on Unix platforms, sockets and pipes are also referenced
by file descriptors.</p>
<p>The <tt class="xref py py-meth docutils literal"><span class="pre">fileno()</span></tt> method can be used to obtain the file descriptor
associated with a <a class="reference internal" href="../glossary.html#term-file-object"><em class="xref std std-term">file object</em></a> when required.  Note that using the file
descriptor directly will bypass the file object methods, ignoring aspects such
as internal buffering of data.</p>
<dl class="function">
<dt id="os.close">
<tt class="descclassname">os.</tt><tt class="descname">close</tt><big>(</big><em>fd</em><big>)</big><a class="headerlink" href="#os.close" title="Permalink to this definition">¶</a></dt>
<dd><p>Close file descriptor <em>fd</em>.</p>
<p>Availability: Unix, Windows.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">This function is intended for low-level I/O and must be applied to a file
descriptor as returned by <a class="reference internal" href="#os.open" title="os.open"><tt class="xref py py-func docutils literal"><span class="pre">os.open()</span></tt></a> or <a class="reference internal" href="#os.pipe" title="os.pipe"><tt class="xref py py-func docutils literal"><span class="pre">pipe()</span></tt></a>.  To close a &#8220;file
object&#8221; returned by the built-in function <a class="reference internal" href="functions.html#open" title="open"><tt class="xref py py-func docutils literal"><span class="pre">open()</span></tt></a> or by <tt class="xref py py-func docutils literal"><span class="pre">popen()</span></tt> or
<a class="reference internal" href="#os.fdopen" title="os.fdopen"><tt class="xref py py-func docutils literal"><span class="pre">fdopen()</span></tt></a>, use its <tt class="xref py py-meth docutils literal"><span class="pre">close()</span></tt> method.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.closerange">
<tt class="descclassname">os.</tt><tt class="descname">closerange</tt><big>(</big><em>fd_low</em>, <em>fd_high</em><big>)</big><a class="headerlink" href="#os.closerange" title="Permalink to this definition">¶</a></dt>
<dd><p>Close all file descriptors from <em>fd_low</em> (inclusive) to <em>fd_high</em> (exclusive),
ignoring errors. Equivalent to:</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="k">for</span> <span class="n">fd</span> <span class="ow">in</span> <span class="nb">range</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>
    <span class="k">try</span><span class="p">:</span>
        <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>
    <span class="k">except</span> <span class="ne">OSError</span><span class="p">:</span>
        <span class="k">pass</span>
</pre></div>
</div>
<p>Availability: Unix, Windows.</p>
</dd></dl>

<dl class="function">
<dt id="os.device_encoding">
<tt class="descclassname">os.</tt><tt class="descname">device_encoding</tt><big>(</big><em>fd</em><big>)</big><a class="headerlink" href="#os.device_encoding" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a string describing the encoding of the device associated with <em>fd</em>
if it is connected to a terminal; else return <a class="reference internal" href="constants.html#None" title="None"><tt class="xref py py-const xref docutils literal"><span class="pre">None</span></tt></a>.</p>
</dd></dl>

<dl class="function">
<dt id="os.dup">
<tt class="descclassname">os.</tt><tt class="descname">dup</tt><big>(</big><em>fd</em><big>)</big><a class="headerlink" href="#os.dup" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a duplicate of file descriptor <em>fd</em>.</p>
<p>Availability: Unix, Windows.</p>
</dd></dl>

<dl class="function">
<dt id="os.dup2">
<tt class="descclassname">os.</tt><tt class="descname">dup2</tt><big>(</big><em>fd</em>, <em>fd2</em><big>)</big><a class="headerlink" href="#os.dup2" title="Permalink to this definition">¶</a></dt>
<dd><p>Duplicate file descriptor <em>fd</em> to <em>fd2</em>, closing the latter first if necessary.</p>
<p>Availability: Unix, Windows.</p>
</dd></dl>

<dl class="function">
<dt id="os.fchmod">
<tt class="descclassname">os.</tt><tt class="descname">fchmod</tt><big>(</big><em>fd</em>, <em>mode</em><big>)</big><a class="headerlink" href="#os.fchmod" title="Permalink to this definition">¶</a></dt>
<dd><p>Change the mode of the file given by <em>fd</em> to the numeric <em>mode</em>.  See the docs
for <a class="reference internal" href="#os.chmod" title="os.chmod"><tt class="xref py py-func docutils literal"><span class="pre">chmod()</span></tt></a> for possible values of <em>mode</em>.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.fchown">
<tt class="descclassname">os.</tt><tt class="descname">fchown</tt><big>(</big><em>fd</em>, <em>uid</em>, <em>gid</em><big>)</big><a class="headerlink" href="#os.fchown" title="Permalink to this definition">¶</a></dt>
<dd><p>Change the owner and group id of the file given by <em>fd</em> to the numeric <em>uid</em>
and <em>gid</em>.  To leave one of the ids unchanged, set it to -1.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.fdatasync">
<tt class="descclassname">os.</tt><tt class="descname">fdatasync</tt><big>(</big><em>fd</em><big>)</big><a class="headerlink" href="#os.fdatasync" title="Permalink to this definition">¶</a></dt>
<dd><p>Force write of file with filedescriptor <em>fd</em> to disk. Does not force update of
metadata.</p>
<p>Availability: Unix.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">This function is not available on MacOS.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.fpathconf">
<tt class="descclassname">os.</tt><tt class="descname">fpathconf</tt><big>(</big><em>fd</em>, <em>name</em><big>)</big><a class="headerlink" href="#os.fpathconf" title="Permalink to this definition">¶</a></dt>
<dd><p>Return system configuration information relevant to an open file. <em>name</em>
specifies the configuration value to retrieve; it may be a string which is the
name of a defined system value; these names are specified in a number of
standards (POSIX.1, Unix 95, Unix 98, and others).  Some platforms define
additional names as well.  The names known to the host operating system are
given in the <tt class="docutils literal"><span class="pre">pathconf_names</span></tt> dictionary.  For configuration variables not
included in that mapping, passing an integer for <em>name</em> is also accepted.</p>
<p>If <em>name</em> is a string and is not known, <a class="reference internal" href="exceptions.html#ValueError" title="ValueError"><tt class="xref py py-exc docutils literal"><span class="pre">ValueError</span></tt></a> is raised.  If a
specific value for <em>name</em> is not supported by the host system, even if it is
included in <tt class="docutils literal"><span class="pre">pathconf_names</span></tt>, an <a class="reference internal" href="exceptions.html#OSError" title="OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a> is raised with
<a class="reference internal" href="errno.html#errno.EINVAL" title="errno.EINVAL"><tt class="xref py py-const docutils literal"><span class="pre">errno.EINVAL</span></tt></a> for the error number.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.fstat">
<tt class="descclassname">os.</tt><tt class="descname">fstat</tt><big>(</big><em>fd</em><big>)</big><a class="headerlink" href="#os.fstat" title="Permalink to this definition">¶</a></dt>
<dd><p>Return status for file descriptor <em>fd</em>, like <a class="reference internal" href="#os.stat" title="os.stat"><tt class="xref py py-func docutils literal"><span class="pre">stat()</span></tt></a>.</p>
<p>Availability: Unix, Windows.</p>
</dd></dl>

<dl class="function">
<dt id="os.fstatvfs">
<tt class="descclassname">os.</tt><tt class="descname">fstatvfs</tt><big>(</big><em>fd</em><big>)</big><a class="headerlink" href="#os.fstatvfs" title="Permalink to this definition">¶</a></dt>
<dd><p>Return information about the filesystem containing the file associated with file
descriptor <em>fd</em>, like <a class="reference internal" href="#os.statvfs" title="os.statvfs"><tt class="xref py py-func docutils literal"><span class="pre">statvfs()</span></tt></a>.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.fsync">
<tt class="descclassname">os.</tt><tt class="descname">fsync</tt><big>(</big><em>fd</em><big>)</big><a class="headerlink" href="#os.fsync" title="Permalink to this definition">¶</a></dt>
<dd><p>Force write of file with filedescriptor <em>fd</em> to disk.  On Unix, this calls the
native <tt class="xref c c-func docutils literal"><span class="pre">fsync()</span></tt> function; on Windows, the MS <tt class="xref c c-func docutils literal"><span class="pre">_commit()</span></tt> function.</p>
<p>If you&#8217;re starting with a buffered Python <a class="reference internal" href="../glossary.html#term-file-object"><em class="xref std std-term">file object</em></a> <em>f</em>, first do
<tt class="docutils literal"><span class="pre">f.flush()</span></tt>, and then do <tt class="docutils literal"><span class="pre">os.fsync(f.fileno())</span></tt>, to ensure that all internal
buffers associated with <em>f</em> are written to disk.</p>
<p>Availability: Unix, and Windows.</p>
</dd></dl>

<dl class="function">
<dt id="os.ftruncate">
<tt class="descclassname">os.</tt><tt class="descname">ftruncate</tt><big>(</big><em>fd</em>, <em>length</em><big>)</big><a class="headerlink" href="#os.ftruncate" title="Permalink to this definition">¶</a></dt>
<dd><p>Truncate the file corresponding to file descriptor <em>fd</em>, so that it is at most
<em>length</em> bytes in size.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.isatty">
<tt class="descclassname">os.</tt><tt class="descname">isatty</tt><big>(</big><em>fd</em><big>)</big><a class="headerlink" href="#os.isatty" title="Permalink to this definition">¶</a></dt>
<dd><p>Return <tt class="xref docutils literal"><span class="pre">True</span></tt> if the file descriptor <em>fd</em> is open and connected to a
tty(-like) device, else <tt class="xref docutils literal"><span class="pre">False</span></tt>.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.lseek">
<tt class="descclassname">os.</tt><tt class="descname">lseek</tt><big>(</big><em>fd</em>, <em>pos</em>, <em>how</em><big>)</big><a class="headerlink" href="#os.lseek" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the current position of file descriptor <em>fd</em> to position <em>pos</em>, modified
by <em>how</em>: <a class="reference internal" href="#os.SEEK_SET" title="os.SEEK_SET"><tt class="xref py py-const docutils literal"><span class="pre">SEEK_SET</span></tt></a> or <tt class="docutils literal"><span class="pre">0</span></tt> to set the position relative to the
beginning of the file; <a class="reference internal" href="#os.SEEK_CUR" title="os.SEEK_CUR"><tt class="xref py py-const docutils literal"><span class="pre">SEEK_CUR</span></tt></a> or <tt class="docutils literal"><span class="pre">1</span></tt> to set it relative to the
current position; <a class="reference internal" href="#os.SEEK_END" title="os.SEEK_END"><tt class="xref py py-const docutils literal"><span class="pre">os.SEEK_END</span></tt></a> or <tt class="docutils literal"><span class="pre">2</span></tt> to set it relative to the end of
the file.</p>
<p>Availability: Unix, Windows.</p>
</dd></dl>

<dl class="data">
<dt id="os.SEEK_SET">
<tt class="descclassname">os.</tt><tt class="descname">SEEK_SET</tt><a class="headerlink" href="#os.SEEK_SET" title="Permalink to this definition">¶</a></dt>
<dt id="os.SEEK_CUR">
<tt class="descclassname">os.</tt><tt class="descname">SEEK_CUR</tt><a class="headerlink" href="#os.SEEK_CUR" title="Permalink to this definition">¶</a></dt>
<dt id="os.SEEK_END">
<tt class="descclassname">os.</tt><tt class="descname">SEEK_END</tt><a class="headerlink" href="#os.SEEK_END" title="Permalink to this definition">¶</a></dt>
<dd><p>Parameters to the <a class="reference internal" href="#os.lseek" title="os.lseek"><tt class="xref py py-func docutils literal"><span class="pre">lseek()</span></tt></a> function. Their values are 0, 1, and 2,
respectively. Availability: Windows, Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.open">
<tt class="descclassname">os.</tt><tt class="descname">open</tt><big>(</big><em>file</em>, <em>flags</em><span class="optional">[</span>, <em>mode</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#os.open" title="Permalink to this definition">¶</a></dt>
<dd><p>Open the file <em>file</em> and set various flags according to <em>flags</em> and possibly
its mode according to <em>mode</em>.  The default <em>mode</em> is <tt class="docutils literal"><span class="pre">0o777</span></tt> (octal), and
the current umask value is first masked out.  Return the file descriptor for
the newly opened file.</p>
<p>For a description of the flag and mode values, see the C run-time documentation;
flag constants (like <a class="reference internal" href="#os.O_RDONLY" title="os.O_RDONLY"><tt class="xref py py-const docutils literal"><span class="pre">O_RDONLY</span></tt></a> and <a class="reference internal" href="#os.O_WRONLY" title="os.O_WRONLY"><tt class="xref py py-const docutils literal"><span class="pre">O_WRONLY</span></tt></a>) are defined in
this module too (see <a class="reference internal" href="#open-constants"><em>open() flag constants</em></a>).  In particular, on Windows adding
<a class="reference internal" href="#os.O_BINARY" title="os.O_BINARY"><tt class="xref py py-const docutils literal"><span class="pre">O_BINARY</span></tt></a> is needed to open files in binary mode.</p>
<p>Availability: Unix, Windows.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">This function is intended for low-level I/O.  For normal usage, use the
built-in function <a class="reference internal" href="functions.html#open" title="open"><tt class="xref py py-func docutils literal"><span class="pre">open()</span></tt></a>, which returns a <a class="reference internal" href="../glossary.html#term-file-object"><em class="xref std std-term">file object</em></a> with
<tt class="xref py py-meth docutils literal"><span class="pre">read()</span></tt> and <tt class="xref py py-meth docutils literal"><span class="pre">write()</span></tt> methods (and many more).  To
wrap a file descriptor in a file object, use <a class="reference internal" href="#os.fdopen" title="os.fdopen"><tt class="xref py py-func docutils literal"><span class="pre">fdopen()</span></tt></a>.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.openpty">
<tt class="descclassname">os.</tt><tt class="descname">openpty</tt><big>(</big><big>)</big><a class="headerlink" href="#os.openpty" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-13">Open a new pseudo-terminal pair. Return a pair of file descriptors <tt class="docutils literal"><span class="pre">(master,</span>
<span class="pre">slave)</span></tt> for the pty and the tty, respectively. For a (slightly) more portable
approach, use the <a class="reference internal" href="pty.html#module-pty" title="pty: Pseudo-Terminal Handling for Linux. (Linux)"><tt class="xref py py-mod docutils literal"><span class="pre">pty</span></tt></a> module.</p>
<p>Availability: some flavors of Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.pipe">
<tt class="descclassname">os.</tt><tt class="descname">pipe</tt><big>(</big><big>)</big><a class="headerlink" href="#os.pipe" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a pipe.  Return a pair of file descriptors <tt class="docutils literal"><span class="pre">(r,</span> <span class="pre">w)</span></tt> usable for reading
and writing, respectively.</p>
<p>Availability: Unix, Windows.</p>
</dd></dl>

<dl class="function">
<dt id="os.read">
<tt class="descclassname">os.</tt><tt class="descname">read</tt><big>(</big><em>fd</em>, <em>n</em><big>)</big><a class="headerlink" href="#os.read" title="Permalink to this definition">¶</a></dt>
<dd><p>Read at most <em>n</em> bytes from file descriptor <em>fd</em>. Return a bytestring containing the
bytes read.  If the end of the file referred to by <em>fd</em> has been reached, an
empty bytes object is returned.</p>
<p>Availability: Unix, Windows.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">This function is intended for low-level I/O and must be applied to a file
descriptor as returned by <a class="reference internal" href="#os.open" title="os.open"><tt class="xref py py-func docutils literal"><span class="pre">os.open()</span></tt></a> or <a class="reference internal" href="#os.pipe" title="os.pipe"><tt class="xref py py-func docutils literal"><span class="pre">pipe()</span></tt></a>.  To read a &#8220;file object&#8221;
returned by the built-in function <a class="reference internal" href="functions.html#open" title="open"><tt class="xref py py-func docutils literal"><span class="pre">open()</span></tt></a> or by <tt class="xref py py-func docutils literal"><span class="pre">popen()</span></tt> or
<a class="reference internal" href="#os.fdopen" title="os.fdopen"><tt class="xref py py-func docutils literal"><span class="pre">fdopen()</span></tt></a>, or <a class="reference internal" href="sys.html#sys.stdin" title="sys.stdin"><tt class="xref py py-data docutils literal"><span class="pre">sys.stdin</span></tt></a>, use its <tt class="xref py py-meth docutils literal"><span class="pre">read()</span></tt> or
<tt class="xref py py-meth docutils literal"><span class="pre">readline()</span></tt> methods.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.tcgetpgrp">
<tt class="descclassname">os.</tt><tt class="descname">tcgetpgrp</tt><big>(</big><em>fd</em><big>)</big><a class="headerlink" href="#os.tcgetpgrp" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the process group associated with the terminal given by <em>fd</em> (an open
file descriptor as returned by <a class="reference internal" href="#os.open" title="os.open"><tt class="xref py py-func docutils literal"><span class="pre">os.open()</span></tt></a>).</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.tcsetpgrp">
<tt class="descclassname">os.</tt><tt class="descname">tcsetpgrp</tt><big>(</big><em>fd</em>, <em>pg</em><big>)</big><a class="headerlink" href="#os.tcsetpgrp" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the process group associated with the terminal given by <em>fd</em> (an open file
descriptor as returned by <a class="reference internal" href="#os.open" title="os.open"><tt class="xref py py-func docutils literal"><span class="pre">os.open()</span></tt></a>) to <em>pg</em>.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.ttyname">
<tt class="descclassname">os.</tt><tt class="descname">ttyname</tt><big>(</big><em>fd</em><big>)</big><a class="headerlink" href="#os.ttyname" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a string which specifies the terminal device associated with
file descriptor <em>fd</em>.  If <em>fd</em> is not associated with a terminal device, an
exception is raised.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.write">
<tt class="descclassname">os.</tt><tt class="descname">write</tt><big>(</big><em>fd</em>, <em>str</em><big>)</big><a class="headerlink" href="#os.write" title="Permalink to this definition">¶</a></dt>
<dd><p>Write the bytestring in <em>str</em> to file descriptor <em>fd</em>. Return the number of
bytes actually written.</p>
<p>Availability: Unix, Windows.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">This function is intended for low-level I/O and must be applied to a file
descriptor as returned by <a class="reference internal" href="#os.open" title="os.open"><tt class="xref py py-func docutils literal"><span class="pre">os.open()</span></tt></a> or <a class="reference internal" href="#os.pipe" title="os.pipe"><tt class="xref py py-func docutils literal"><span class="pre">pipe()</span></tt></a>.  To write a &#8220;file
object&#8221; returned by the built-in function <a class="reference internal" href="functions.html#open" title="open"><tt class="xref py py-func docutils literal"><span class="pre">open()</span></tt></a> or by <tt class="xref py py-func docutils literal"><span class="pre">popen()</span></tt> or
<a class="reference internal" href="#os.fdopen" title="os.fdopen"><tt class="xref py py-func docutils literal"><span class="pre">fdopen()</span></tt></a>, or <a class="reference internal" href="sys.html#sys.stdout" title="sys.stdout"><tt class="xref py py-data docutils literal"><span class="pre">sys.stdout</span></tt></a> or <a class="reference internal" href="sys.html#sys.stderr" title="sys.stderr"><tt class="xref py py-data docutils literal"><span class="pre">sys.stderr</span></tt></a>, use its
<tt class="xref py py-meth docutils literal"><span class="pre">write()</span></tt> method.</p>
</div>
</dd></dl>

<div class="section" id="open-flag-constants">
<span id="open-constants"></span><h3>15.1.4.1. <tt class="docutils literal"><span class="pre">open()</span></tt> flag constants<a class="headerlink" href="#open-flag-constants" title="Permalink to this headline">¶</a></h3>
<p>The following constants are options for the <em>flags</em> parameter to the
<a class="reference internal" href="#os.open" title="os.open"><tt class="xref py py-func docutils literal"><span class="pre">open()</span></tt></a> function.  They can be combined using the bitwise OR operator
<tt class="docutils literal"><span class="pre">|</span></tt>.  Some of them are not available on all platforms.  For descriptions of
their availability and use, consult the <em class="manpage">open(2)</em> manual page on Unix
or <a class="reference external" href="http://msdn.microsoft.com/en-us/library/z0kc8e3z.aspx">the MSDN</a> on Windows.</p>
<dl class="data">
<dt id="os.O_RDONLY">
<tt class="descclassname">os.</tt><tt class="descname">O_RDONLY</tt><a class="headerlink" href="#os.O_RDONLY" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_WRONLY">
<tt class="descclassname">os.</tt><tt class="descname">O_WRONLY</tt><a class="headerlink" href="#os.O_WRONLY" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_RDWR">
<tt class="descclassname">os.</tt><tt class="descname">O_RDWR</tt><a class="headerlink" href="#os.O_RDWR" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_APPEND">
<tt class="descclassname">os.</tt><tt class="descname">O_APPEND</tt><a class="headerlink" href="#os.O_APPEND" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_CREAT">
<tt class="descclassname">os.</tt><tt class="descname">O_CREAT</tt><a class="headerlink" href="#os.O_CREAT" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_EXCL">
<tt class="descclassname">os.</tt><tt class="descname">O_EXCL</tt><a class="headerlink" href="#os.O_EXCL" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_TRUNC">
<tt class="descclassname">os.</tt><tt class="descname">O_TRUNC</tt><a class="headerlink" href="#os.O_TRUNC" title="Permalink to this definition">¶</a></dt>
<dd><p>These constants are available on Unix and Windows.</p>
</dd></dl>

<dl class="data">
<dt id="os.O_DSYNC">
<tt class="descclassname">os.</tt><tt class="descname">O_DSYNC</tt><a class="headerlink" href="#os.O_DSYNC" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_RSYNC">
<tt class="descclassname">os.</tt><tt class="descname">O_RSYNC</tt><a class="headerlink" href="#os.O_RSYNC" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_SYNC">
<tt class="descclassname">os.</tt><tt class="descname">O_SYNC</tt><a class="headerlink" href="#os.O_SYNC" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_NDELAY">
<tt class="descclassname">os.</tt><tt class="descname">O_NDELAY</tt><a class="headerlink" href="#os.O_NDELAY" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_NONBLOCK">
<tt class="descclassname">os.</tt><tt class="descname">O_NONBLOCK</tt><a class="headerlink" href="#os.O_NONBLOCK" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_NOCTTY">
<tt class="descclassname">os.</tt><tt class="descname">O_NOCTTY</tt><a class="headerlink" href="#os.O_NOCTTY" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_SHLOCK">
<tt class="descclassname">os.</tt><tt class="descname">O_SHLOCK</tt><a class="headerlink" href="#os.O_SHLOCK" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_EXLOCK">
<tt class="descclassname">os.</tt><tt class="descname">O_EXLOCK</tt><a class="headerlink" href="#os.O_EXLOCK" title="Permalink to this definition">¶</a></dt>
<dd><p>These constants are only available on Unix.</p>
</dd></dl>

<dl class="data">
<dt id="os.O_BINARY">
<tt class="descclassname">os.</tt><tt class="descname">O_BINARY</tt><a class="headerlink" href="#os.O_BINARY" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_NOINHERIT">
<tt class="descclassname">os.</tt><tt class="descname">O_NOINHERIT</tt><a class="headerlink" href="#os.O_NOINHERIT" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_SHORT_LIVED">
<tt class="descclassname">os.</tt><tt class="descname">O_SHORT_LIVED</tt><a class="headerlink" href="#os.O_SHORT_LIVED" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_TEMPORARY">
<tt class="descclassname">os.</tt><tt class="descname">O_TEMPORARY</tt><a class="headerlink" href="#os.O_TEMPORARY" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_RANDOM">
<tt class="descclassname">os.</tt><tt class="descname">O_RANDOM</tt><a class="headerlink" href="#os.O_RANDOM" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_SEQUENTIAL">
<tt class="descclassname">os.</tt><tt class="descname">O_SEQUENTIAL</tt><a class="headerlink" href="#os.O_SEQUENTIAL" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_TEXT">
<tt class="descclassname">os.</tt><tt class="descname">O_TEXT</tt><a class="headerlink" href="#os.O_TEXT" title="Permalink to this definition">¶</a></dt>
<dd><p>These constants are only available on Windows.</p>
</dd></dl>

<dl class="data">
<dt id="os.O_ASYNC">
<tt class="descclassname">os.</tt><tt class="descname">O_ASYNC</tt><a class="headerlink" href="#os.O_ASYNC" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_DIRECT">
<tt class="descclassname">os.</tt><tt class="descname">O_DIRECT</tt><a class="headerlink" href="#os.O_DIRECT" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_DIRECTORY">
<tt class="descclassname">os.</tt><tt class="descname">O_DIRECTORY</tt><a class="headerlink" href="#os.O_DIRECTORY" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_NOFOLLOW">
<tt class="descclassname">os.</tt><tt class="descname">O_NOFOLLOW</tt><a class="headerlink" href="#os.O_NOFOLLOW" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_NOATIME">
<tt class="descclassname">os.</tt><tt class="descname">O_NOATIME</tt><a class="headerlink" href="#os.O_NOATIME" title="Permalink to this definition">¶</a></dt>
<dd><p>These constants are GNU extensions and not present if they are not defined by
the C library.</p>
</dd></dl>

</div>
</div>
<div class="section" id="files-and-directories">
<span id="os-file-dir"></span><h2>15.1.5. Files and Directories<a class="headerlink" href="#files-and-directories" title="Permalink to this headline">¶</a></h2>
<dl class="function">
<dt id="os.access">
<tt class="descclassname">os.</tt><tt class="descname">access</tt><big>(</big><em>path</em>, <em>mode</em><big>)</big><a class="headerlink" href="#os.access" title="Permalink to this definition">¶</a></dt>
<dd><p>Use the real uid/gid to test for access to <em>path</em>.  Note that most operations
will use the effective uid/gid, therefore this routine can be used in a
suid/sgid environment to test if the invoking user has the specified access to
<em>path</em>.  <em>mode</em> should be <a class="reference internal" href="#os.F_OK" title="os.F_OK"><tt class="xref py py-const docutils literal"><span class="pre">F_OK</span></tt></a> to test the existence of <em>path</em>, or it
can be the inclusive OR of one or more of <a class="reference internal" href="#os.R_OK" title="os.R_OK"><tt class="xref py py-const docutils literal"><span class="pre">R_OK</span></tt></a>, <a class="reference internal" href="#os.W_OK" title="os.W_OK"><tt class="xref py py-const docutils literal"><span class="pre">W_OK</span></tt></a>, and
<a class="reference internal" href="#os.X_OK" title="os.X_OK"><tt class="xref py py-const docutils literal"><span class="pre">X_OK</span></tt></a> to test permissions.  Return <a class="reference internal" href="constants.html#True" title="True"><tt class="xref py py-const xref docutils literal"><span class="pre">True</span></tt></a> if access is allowed,
<a class="reference internal" href="constants.html#False" title="False"><tt class="xref py py-const xref docutils literal"><span class="pre">False</span></tt></a> if not. See the Unix man page <em class="manpage">access(2)</em> for more
information.</p>
<p>Availability: Unix, Windows.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p>Using <a class="reference internal" href="#os.access" title="os.access"><tt class="xref py py-func docutils literal"><span class="pre">access()</span></tt></a> to check if a user is authorized to e.g. open a file
before actually doing so using <a class="reference internal" href="functions.html#open" title="open"><tt class="xref py py-func docutils literal"><span class="pre">open()</span></tt></a> creates a security hole,
because the user might exploit the short time interval between checking
and opening the file to manipulate it. It&#8217;s preferable to use <a class="reference internal" href="../glossary.html#term-eafp"><em class="xref std std-term">EAFP</em></a>
techniques. For example:</p>
<div class="highlight-python3"><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="s">&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>
    <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="s">&quot;myfile&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">fp</span><span class="p">:</span>
        <span class="k">return</span> <span class="n">fp</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
<span class="k">return</span> <span class="s">&quot;some default data&quot;</span>
</pre></div>
</div>
<p>is better written as:</p>
<div class="last highlight-python3"><div class="highlight"><pre><span class="k">try</span><span class="p">:</span>
    <span class="n">fp</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="s">&quot;myfile&quot;</span><span class="p">)</span>
<span class="k">except</span> <span class="ne">IOError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
    <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">EACCESS</span><span class="p">:</span>
        <span class="k">return</span> <span class="s">&quot;some default data&quot;</span>
    <span class="c"># Not a permission error.</span>
    <span class="k">raise</span>
<span class="k">else</span><span class="p">:</span>
    <span class="k">with</span> <span class="n">fp</span><span class="p">:</span>
        <span class="k">return</span> <span class="n">fp</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
</pre></div>
</div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">I/O operations may fail even when <a class="reference internal" href="#os.access" title="os.access"><tt class="xref py py-func docutils literal"><span class="pre">access()</span></tt></a> indicates that they would
succeed, particularly for operations on network filesystems which may have
permissions semantics beyond the usual POSIX permission-bit model.</p>
</div>
</dd></dl>

<dl class="data">
<dt id="os.F_OK">
<tt class="descclassname">os.</tt><tt class="descname">F_OK</tt><a class="headerlink" href="#os.F_OK" title="Permalink to this definition">¶</a></dt>
<dd><p>Value to pass as the <em>mode</em> parameter of <a class="reference internal" href="#os.access" title="os.access"><tt class="xref py py-func docutils literal"><span class="pre">access()</span></tt></a> to test the existence of
<em>path</em>.</p>
</dd></dl>

<dl class="data">
<dt id="os.R_OK">
<tt class="descclassname">os.</tt><tt class="descname">R_OK</tt><a class="headerlink" href="#os.R_OK" title="Permalink to this definition">¶</a></dt>
<dd><p>Value to include in the <em>mode</em> parameter of <a class="reference internal" href="#os.access" title="os.access"><tt class="xref py py-func docutils literal"><span class="pre">access()</span></tt></a> to test the
readability of <em>path</em>.</p>
</dd></dl>

<dl class="data">
<dt id="os.W_OK">
<tt class="descclassname">os.</tt><tt class="descname">W_OK</tt><a class="headerlink" href="#os.W_OK" title="Permalink to this definition">¶</a></dt>
<dd><p>Value to include in the <em>mode</em> parameter of <a class="reference internal" href="#os.access" title="os.access"><tt class="xref py py-func docutils literal"><span class="pre">access()</span></tt></a> to test the
writability of <em>path</em>.</p>
</dd></dl>

<dl class="data">
<dt id="os.X_OK">
<tt class="descclassname">os.</tt><tt class="descname">X_OK</tt><a class="headerlink" href="#os.X_OK" title="Permalink to this definition">¶</a></dt>
<dd><p>Value to include in the <em>mode</em> parameter of <a class="reference internal" href="#os.access" title="os.access"><tt class="xref py py-func docutils literal"><span class="pre">access()</span></tt></a> to determine if
<em>path</em> can be executed.</p>
</dd></dl>

<dl class="function">
<dt id="os.chdir">
<tt class="descclassname">os.</tt><tt class="descname">chdir</tt><big>(</big><em>path</em><big>)</big><a class="headerlink" href="#os.chdir" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-14">Change the current working directory to <em>path</em>.</p>
<p>Availability: Unix, Windows.</p>
</dd></dl>

<dl class="function">
<dt id="os.fchdir">
<tt class="descclassname">os.</tt><tt class="descname">fchdir</tt><big>(</big><em>fd</em><big>)</big><a class="headerlink" href="#os.fchdir" title="Permalink to this definition">¶</a></dt>
<dd><p>Change the current working directory to the directory represented by the file
descriptor <em>fd</em>.  The descriptor must refer to an opened directory, not an open
file.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.getcwd">
<tt class="descclassname">os.</tt><tt class="descname">getcwd</tt><big>(</big><big>)</big><a class="headerlink" href="#os.getcwd" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a string representing the current working directory.</p>
<p>Availability: Unix, Windows.</p>
</dd></dl>

<dl class="function">
<dt id="os.getcwdb">
<tt class="descclassname">os.</tt><tt class="descname">getcwdb</tt><big>(</big><big>)</big><a class="headerlink" href="#os.getcwdb" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a bytestring representing the current working directory.</p>
<p>Availability: Unix, Windows.</p>
</dd></dl>

<dl class="function">
<dt id="os.chflags">
<tt class="descclassname">os.</tt><tt class="descname">chflags</tt><big>(</big><em>path</em>, <em>flags</em><big>)</big><a class="headerlink" href="#os.chflags" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the flags of <em>path</em> to the numeric <em>flags</em>. <em>flags</em> may take a combination
(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()."><tt class="xref py py-mod docutils literal"><span class="pre">stat</span></tt></a> module):</p>
<ul class="simple">
<li><a class="reference internal" href="stat.html#stat.UF_NODUMP" title="stat.UF_NODUMP"><tt class="xref py py-data docutils literal"><span class="pre">stat.UF_NODUMP</span></tt></a></li>
<li><a class="reference internal" href="stat.html#stat.UF_IMMUTABLE" title="stat.UF_IMMUTABLE"><tt class="xref py py-data docutils literal"><span class="pre">stat.UF_IMMUTABLE</span></tt></a></li>
<li><a class="reference internal" href="stat.html#stat.UF_APPEND" title="stat.UF_APPEND"><tt class="xref py py-data docutils literal"><span class="pre">stat.UF_APPEND</span></tt></a></li>
<li><a class="reference internal" href="stat.html#stat.UF_OPAQUE" title="stat.UF_OPAQUE"><tt class="xref py py-data docutils literal"><span class="pre">stat.UF_OPAQUE</span></tt></a></li>
<li><a class="reference internal" href="stat.html#stat.UF_NOUNLINK" title="stat.UF_NOUNLINK"><tt class="xref py py-data docutils literal"><span class="pre">stat.UF_NOUNLINK</span></tt></a></li>
<li><a class="reference internal" href="stat.html#stat.UF_COMPRESSED" title="stat.UF_COMPRESSED"><tt class="xref py py-data docutils literal"><span class="pre">stat.UF_COMPRESSED</span></tt></a></li>
<li><a class="reference internal" href="stat.html#stat.UF_HIDDEN" title="stat.UF_HIDDEN"><tt class="xref py py-data docutils literal"><span class="pre">stat.UF_HIDDEN</span></tt></a></li>
<li><a class="reference internal" href="stat.html#stat.SF_ARCHIVED" title="stat.SF_ARCHIVED"><tt class="xref py py-data docutils literal"><span class="pre">stat.SF_ARCHIVED</span></tt></a></li>
<li><a class="reference internal" href="stat.html#stat.SF_IMMUTABLE" title="stat.SF_IMMUTABLE"><tt class="xref py py-data docutils literal"><span class="pre">stat.SF_IMMUTABLE</span></tt></a></li>
<li><a class="reference internal" href="stat.html#stat.SF_APPEND" title="stat.SF_APPEND"><tt class="xref py py-data docutils literal"><span class="pre">stat.SF_APPEND</span></tt></a></li>
<li><a class="reference internal" href="stat.html#stat.SF_NOUNLINK" title="stat.SF_NOUNLINK"><tt class="xref py py-data docutils literal"><span class="pre">stat.SF_NOUNLINK</span></tt></a></li>
<li><a class="reference internal" href="stat.html#stat.SF_SNAPSHOT" title="stat.SF_SNAPSHOT"><tt class="xref py py-data docutils literal"><span class="pre">stat.SF_SNAPSHOT</span></tt></a></li>
</ul>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.chroot">
<tt class="descclassname">os.</tt><tt class="descname">chroot</tt><big>(</big><em>path</em><big>)</big><a class="headerlink" href="#os.chroot" title="Permalink to this definition">¶</a></dt>
<dd><p>Change the root directory of the current process to <em>path</em>. Availability:
Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.chmod">
<tt class="descclassname">os.</tt><tt class="descname">chmod</tt><big>(</big><em>path</em>, <em>mode</em><big>)</big><a class="headerlink" href="#os.chmod" title="Permalink to this definition">¶</a></dt>
<dd><p>Change the mode of <em>path</em> to the numeric <em>mode</em>. <em>mode</em> may take one 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()."><tt class="xref py py-mod docutils literal"><span class="pre">stat</span></tt></a> module) or bitwise ORed
combinations of them:</p>
<ul class="simple">
<li><a class="reference internal" href="stat.html#stat.S_ISUID" title="stat.S_ISUID"><tt class="xref py py-data docutils literal"><span class="pre">stat.S_ISUID</span></tt></a></li>
<li><a class="reference internal" href="stat.html#stat.S_ISGID" title="stat.S_ISGID"><tt class="xref py py-data docutils literal"><span class="pre">stat.S_ISGID</span></tt></a></li>
<li><a class="reference internal" href="stat.html#stat.S_ENFMT" title="stat.S_ENFMT"><tt class="xref py py-data docutils literal"><span class="pre">stat.S_ENFMT</span></tt></a></li>
<li><a class="reference internal" href="stat.html#stat.S_ISVTX" title="stat.S_ISVTX"><tt class="xref py py-data docutils literal"><span class="pre">stat.S_ISVTX</span></tt></a></li>
<li><a class="reference internal" href="stat.html#stat.S_IREAD" title="stat.S_IREAD"><tt class="xref py py-data docutils literal"><span class="pre">stat.S_IREAD</span></tt></a></li>
<li><a class="reference internal" href="stat.html#stat.S_IWRITE" title="stat.S_IWRITE"><tt class="xref py py-data docutils literal"><span class="pre">stat.S_IWRITE</span></tt></a></li>
<li><a class="reference internal" href="stat.html#stat.S_IEXEC" title="stat.S_IEXEC"><tt class="xref py py-data docutils literal"><span class="pre">stat.S_IEXEC</span></tt></a></li>
<li><a class="reference internal" href="stat.html#stat.S_IRWXU" title="stat.S_IRWXU"><tt class="xref py py-data docutils literal"><span class="pre">stat.S_IRWXU</span></tt></a></li>
<li><a class="reference internal" href="stat.html#stat.S_IRUSR" title="stat.S_IRUSR"><tt class="xref py py-data docutils literal"><span class="pre">stat.S_IRUSR</span></tt></a></li>
<li><a class="reference internal" href="stat.html#stat.S_IWUSR" title="stat.S_IWUSR"><tt class="xref py py-data docutils literal"><span class="pre">stat.S_IWUSR</span></tt></a></li>
<li><a class="reference internal" href="stat.html#stat.S_IXUSR" title="stat.S_IXUSR"><tt class="xref py py-data docutils literal"><span class="pre">stat.S_IXUSR</span></tt></a></li>
<li><a class="reference internal" href="stat.html#stat.S_IRWXG" title="stat.S_IRWXG"><tt class="xref py py-data docutils literal"><span class="pre">stat.S_IRWXG</span></tt></a></li>
<li><a class="reference internal" href="stat.html#stat.S_IRGRP" title="stat.S_IRGRP"><tt class="xref py py-data docutils literal"><span class="pre">stat.S_IRGRP</span></tt></a></li>
<li><a class="reference internal" href="stat.html#stat.S_IWGRP" title="stat.S_IWGRP"><tt class="xref py py-data docutils literal"><span class="pre">stat.S_IWGRP</span></tt></a></li>
<li><a class="reference internal" href="stat.html#stat.S_IXGRP" title="stat.S_IXGRP"><tt class="xref py py-data docutils literal"><span class="pre">stat.S_IXGRP</span></tt></a></li>
<li><a class="reference internal" href="stat.html#stat.S_IRWXO" title="stat.S_IRWXO"><tt class="xref py py-data docutils literal"><span class="pre">stat.S_IRWXO</span></tt></a></li>
<li><a class="reference internal" href="stat.html#stat.S_IROTH" title="stat.S_IROTH"><tt class="xref py py-data docutils literal"><span class="pre">stat.S_IROTH</span></tt></a></li>
<li><a class="reference internal" href="stat.html#stat.S_IWOTH" title="stat.S_IWOTH"><tt class="xref py py-data docutils literal"><span class="pre">stat.S_IWOTH</span></tt></a></li>
<li><a class="reference internal" href="stat.html#stat.S_IXOTH" title="stat.S_IXOTH"><tt class="xref py py-data docutils literal"><span class="pre">stat.S_IXOTH</span></tt></a></li>
</ul>
<p>Availability: Unix, Windows.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Although Windows supports <a class="reference internal" href="#os.chmod" title="os.chmod"><tt class="xref py py-func docutils literal"><span class="pre">chmod()</span></tt></a>, you can only  set the file&#8217;s read-only
flag with it (via the <tt class="docutils literal"><span class="pre">stat.S_IWRITE</span></tt>  and <tt class="docutils literal"><span class="pre">stat.S_IREAD</span></tt>
constants or a corresponding integer value).  All other bits are
ignored.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.chown">
<tt class="descclassname">os.</tt><tt class="descname">chown</tt><big>(</big><em>path</em>, <em>uid</em>, <em>gid</em><big>)</big><a class="headerlink" href="#os.chown" title="Permalink to this definition">¶</a></dt>
<dd><p>Change the owner and group id of <em>path</em> to the numeric <em>uid</em> and <em>gid</em>. To leave
one of the ids unchanged, set it to -1.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.lchflags">
<tt class="descclassname">os.</tt><tt class="descname">lchflags</tt><big>(</big><em>path</em>, <em>flags</em><big>)</big><a class="headerlink" href="#os.lchflags" title="Permalink to this definition">¶</a></dt>
<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"><tt class="xref py py-func docutils literal"><span class="pre">chflags()</span></tt></a>, but do not
follow symbolic links.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.lchmod">
<tt class="descclassname">os.</tt><tt class="descname">lchmod</tt><big>(</big><em>path</em>, <em>mode</em><big>)</big><a class="headerlink" href="#os.lchmod" title="Permalink to this definition">¶</a></dt>
<dd><p>Change the mode of <em>path</em> to the numeric <em>mode</em>. If path is a symlink, this
affects the symlink rather than the target. See the docs for <a class="reference internal" href="#os.chmod" title="os.chmod"><tt class="xref py py-func docutils literal"><span class="pre">chmod()</span></tt></a>
for possible values of <em>mode</em>.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.lchown">
<tt class="descclassname">os.</tt><tt class="descname">lchown</tt><big>(</big><em>path</em>, <em>uid</em>, <em>gid</em><big>)</big><a class="headerlink" href="#os.lchown" title="Permalink to this definition">¶</a></dt>
<dd><p>Change the owner and group id of <em>path</em> to the numeric <em>uid</em> and <em>gid</em>. This
function will not follow symbolic links.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.link">
<tt class="descclassname">os.</tt><tt class="descname">link</tt><big>(</big><em>source</em>, <em>link_name</em><big>)</big><a class="headerlink" href="#os.link" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a hard link pointing to <em>source</em> named <em>link_name</em>.</p>
<p>Availability: Unix, Windows.</p>
<p class="versionchanged">
<span class="versionmodified">Changed in version 3.2: </span>Added Windows support.</p>
</dd></dl>

<dl class="function">
<dt id="os.listdir">
<tt class="descclassname">os.</tt><tt class="descname">listdir</tt><big>(</big><em>path='.'</em><big>)</big><a class="headerlink" href="#os.listdir" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a list containing the names of the entries in the directory given by
<em>path</em> (default: <tt class="docutils literal"><span class="pre">'.'</span></tt>).  The list is in arbitrary order.  It does not include the special
entries <tt class="docutils literal"><span class="pre">'.'</span></tt> and <tt class="docutils literal"><span class="pre">'..'</span></tt> even if they are present in the directory.</p>
<p>This function can be called with a bytes or string argument, and returns
filenames of the same datatype.</p>
<p>Availability: Unix, Windows.</p>
<p class="versionchanged">
<span class="versionmodified">Changed in version 3.2: </span>The <em>path</em> parameter became optional.</p>
</dd></dl>

<dl class="function">
<dt id="os.lstat">
<tt class="descclassname">os.</tt><tt class="descname">lstat</tt><big>(</big><em>path</em><big>)</big><a class="headerlink" href="#os.lstat" title="Permalink to this definition">¶</a></dt>
<dd><p>Perform the equivalent of an <tt class="xref c c-func docutils literal"><span class="pre">lstat()</span></tt> system call on the given path.
Similar to <a class="reference internal" href="#os.stat" title="os.stat"><tt class="xref py py-func docutils literal"><span class="pre">stat()</span></tt></a>, but does not follow symbolic links.  On
platforms that do not support symbolic links, this is an alias for
<a class="reference internal" href="#os.stat" title="os.stat"><tt class="xref py py-func docutils literal"><span class="pre">stat()</span></tt></a>.</p>
<p class="versionchanged">
<span class="versionmodified">Changed in version 3.2: </span>Added support for Windows 6.0 (Vista) symbolic links.</p>
</dd></dl>

<dl class="function">
<dt id="os.mkfifo">
<tt class="descclassname">os.</tt><tt class="descname">mkfifo</tt><big>(</big><em>path</em><span class="optional">[</span>, <em>mode</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#os.mkfifo" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a FIFO (a named pipe) named <em>path</em> with numeric mode <em>mode</em>.  The
default <em>mode</em> is <tt class="docutils literal"><span class="pre">0o666</span></tt> (octal).  The current umask value is first masked
out from the mode.</p>
<p>FIFOs are pipes that can be accessed like regular files.  FIFOs exist until they
are deleted (for example with <a class="reference internal" href="#os.unlink" title="os.unlink"><tt class="xref py py-func docutils literal"><span class="pre">os.unlink()</span></tt></a>). Generally, FIFOs are used as
rendezvous between &#8220;client&#8221; and &#8220;server&#8221; type processes: the server opens the
FIFO for reading, and the client opens it for writing.  Note that <a class="reference internal" href="#os.mkfifo" title="os.mkfifo"><tt class="xref py py-func docutils literal"><span class="pre">mkfifo()</span></tt></a>
doesn&#8217;t open the FIFO &#8212; it just creates the rendezvous point.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.mknod">
<tt class="descclassname">os.</tt><tt class="descname">mknod</tt><big>(</big><em>filename</em><span class="optional">[</span>, <em>mode=0o600</em><span class="optional">[</span>, <em>device</em><span class="optional">]</span><span class="optional">]</span><big>)</big><a class="headerlink" href="#os.mknod" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a filesystem node (file, device special file or named pipe) named
<em>filename</em>. <em>mode</em> specifies both the permissions to use and the type of node
to be created, being combined (bitwise OR) with one of <tt class="docutils literal"><span class="pre">stat.S_IFREG</span></tt>,
<tt class="docutils literal"><span class="pre">stat.S_IFCHR</span></tt>, <tt class="docutils literal"><span class="pre">stat.S_IFBLK</span></tt>, and <tt class="docutils literal"><span class="pre">stat.S_IFIFO</span></tt> (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()."><tt class="xref py py-mod docutils literal"><span class="pre">stat</span></tt></a>).  For <tt class="docutils literal"><span class="pre">stat.S_IFCHR</span></tt> and <tt class="docutils literal"><span class="pre">stat.S_IFBLK</span></tt>,
<em>device</em> defines the newly created device special file (probably using
<a class="reference internal" href="#os.makedev" title="os.makedev"><tt class="xref py py-func docutils literal"><span class="pre">os.makedev()</span></tt></a>), otherwise it is ignored.</p>
</dd></dl>

<dl class="function">
<dt id="os.major">
<tt class="descclassname">os.</tt><tt class="descname">major</tt><big>(</big><em>device</em><big>)</big><a class="headerlink" href="#os.major" title="Permalink to this definition">¶</a></dt>
<dd><p>Extract the device major number from a raw device number (usually the
<tt class="xref py py-attr docutils literal"><span class="pre">st_dev</span></tt> or <tt class="xref py py-attr docutils literal"><span class="pre">st_rdev</span></tt> field from <tt class="xref c c-type docutils literal"><span class="pre">stat</span></tt>).</p>
</dd></dl>

<dl class="function">
<dt id="os.minor">
<tt class="descclassname">os.</tt><tt class="descname">minor</tt><big>(</big><em>device</em><big>)</big><a class="headerlink" href="#os.minor" title="Permalink to this definition">¶</a></dt>
<dd><p>Extract the device minor number from a raw device number (usually the
<tt class="xref py py-attr docutils literal"><span class="pre">st_dev</span></tt> or <tt class="xref py py-attr docutils literal"><span class="pre">st_rdev</span></tt> field from <tt class="xref c c-type docutils literal"><span class="pre">stat</span></tt>).</p>
</dd></dl>

<dl class="function">
<dt id="os.makedev">
<tt class="descclassname">os.</tt><tt class="descname">makedev</tt><big>(</big><em>major</em>, <em>minor</em><big>)</big><a class="headerlink" href="#os.makedev" title="Permalink to this definition">¶</a></dt>
<dd><p>Compose a raw device number from the major and minor device numbers.</p>
</dd></dl>

<dl class="function">
<dt id="os.mkdir">
<tt class="descclassname">os.</tt><tt class="descname">mkdir</tt><big>(</big><em>path</em><span class="optional">[</span>, <em>mode</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#os.mkdir" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a directory named <em>path</em> with numeric mode <em>mode</em>. The default <em>mode</em>
is <tt class="docutils literal"><span class="pre">0o777</span></tt> (octal).  On some systems, <em>mode</em> is ignored.  Where it is used,
the current umask value is first masked out.  If the directory already
exists, <a class="reference internal" href="exceptions.html#OSError" title="OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a> is raised.</p>
<p>It is also possible to create temporary directories; see the
<a class="reference internal" href="tempfile.html#module-tempfile" title="tempfile: Generate temporary files and directories."><tt class="xref py py-mod docutils literal"><span class="pre">tempfile</span></tt></a> module&#8217;s <a class="reference internal" href="tempfile.html#tempfile.mkdtemp" title="tempfile.mkdtemp"><tt class="xref py py-func docutils literal"><span class="pre">tempfile.mkdtemp()</span></tt></a> function.</p>
<p>Availability: Unix, Windows.</p>
</dd></dl>

<dl class="function">
<dt id="os.makedirs">
<tt class="descclassname">os.</tt><tt class="descname">makedirs</tt><big>(</big><em>path</em>, <em>mode=0o777</em>, <em>exist_ok=False</em><big>)</big><a class="headerlink" href="#os.makedirs" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-15">Recursive directory creation function.  Like <a class="reference internal" href="#os.mkdir" title="os.mkdir"><tt class="xref py py-func docutils literal"><span class="pre">mkdir()</span></tt></a>, but makes all
intermediate-level directories needed to contain the leaf directory.  If
the target directory with the same mode as specified already exists,
raises an <a class="reference internal" href="exceptions.html#OSError" title="OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a> exception if <em>exist_ok</em> is False, otherwise no
exception is raised.  If the directory cannot be created in other cases,
raises an <a class="reference internal" href="exceptions.html#OSError" title="OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a> exception.  The default <em>mode</em> is <tt class="docutils literal"><span class="pre">0o777</span></tt> (octal).
On some systems, <em>mode</em> is ignored.  Where it is used, the current umask
value is first masked out.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last"><a class="reference internal" href="#os.makedirs" title="os.makedirs"><tt class="xref py py-func docutils literal"><span class="pre">makedirs()</span></tt></a> will become confused if the path elements to create
include <a class="reference internal" href="#os.pardir" title="os.pardir"><tt class="xref py py-data docutils literal"><span class="pre">pardir</span></tt></a>.</p>
</div>
<p>This function handles UNC paths correctly.</p>
<p class="versionadded">
<span class="versionmodified">New in version 3.2: </span>The <em>exist_ok</em> parameter.</p>
</dd></dl>

<dl class="function">
<dt id="os.pathconf">
<tt class="descclassname">os.</tt><tt class="descname">pathconf</tt><big>(</big><em>path</em>, <em>name</em><big>)</big><a class="headerlink" href="#os.pathconf" title="Permalink to this definition">¶</a></dt>
<dd><p>Return system configuration information relevant to a named file. <em>name</em>
specifies the configuration value to retrieve; it may be a string which is the
name of a defined system value; these names are specified in a number of
standards (POSIX.1, Unix 95, Unix 98, and others).  Some platforms define
additional names as well.  The names known to the host operating system are
given in the <tt class="docutils literal"><span class="pre">pathconf_names</span></tt> dictionary.  For configuration variables not
included in that mapping, passing an integer for <em>name</em> is also accepted.</p>
<p>If <em>name</em> is a string and is not known, <a class="reference internal" href="exceptions.html#ValueError" title="ValueError"><tt class="xref py py-exc docutils literal"><span class="pre">ValueError</span></tt></a> is raised.  If a
specific value for <em>name</em> is not supported by the host system, even if it is
included in <tt class="docutils literal"><span class="pre">pathconf_names</span></tt>, an <a class="reference internal" href="exceptions.html#OSError" title="OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a> is raised with
<a class="reference internal" href="errno.html#errno.EINVAL" title="errno.EINVAL"><tt class="xref py py-const docutils literal"><span class="pre">errno.EINVAL</span></tt></a> for the error number.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="data">
<dt id="os.pathconf_names">
<tt class="descclassname">os.</tt><tt class="descname">pathconf_names</tt><a class="headerlink" href="#os.pathconf_names" title="Permalink to this definition">¶</a></dt>
<dd><p>Dictionary mapping names accepted by <a class="reference internal" href="#os.pathconf" title="os.pathconf"><tt class="xref py py-func docutils literal"><span class="pre">pathconf()</span></tt></a> and <a class="reference internal" href="#os.fpathconf" title="os.fpathconf"><tt class="xref py py-func docutils literal"><span class="pre">fpathconf()</span></tt></a> to
the integer values defined for those names by the host operating system.  This
can be used to determine the set of names known to the system. Availability:
Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.readlink">
<tt class="descclassname">os.</tt><tt class="descname">readlink</tt><big>(</big><em>path</em><big>)</big><a class="headerlink" href="#os.readlink" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a string representing the path to which the symbolic link points.  The
result may be either an absolute or relative pathname; if it is relative, it may
be converted to an absolute pathname using <tt class="docutils literal"><span class="pre">os.path.join(os.path.dirname(path),</span>
<span class="pre">result)</span></tt>.</p>
<p>If the <em>path</em> is a string object, the result will also be a string object,
and the call may raise an UnicodeDecodeError. If the <em>path</em> is a bytes
object, the result will be a bytes object.</p>
<p>Availability: Unix, Windows</p>
<p class="versionchanged">
<span class="versionmodified">Changed in version 3.2: </span>Added support for Windows 6.0 (Vista) symbolic links.</p>
</dd></dl>

<dl class="function">
<dt id="os.remove">
<tt class="descclassname">os.</tt><tt class="descname">remove</tt><big>(</big><em>path</em><big>)</big><a class="headerlink" href="#os.remove" title="Permalink to this definition">¶</a></dt>
<dd><p>Remove (delete) the file <em>path</em>.  If <em>path</em> is a directory, <a class="reference internal" href="exceptions.html#OSError" title="OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a> is
raised; see <a class="reference internal" href="#os.rmdir" title="os.rmdir"><tt class="xref py py-func docutils literal"><span class="pre">rmdir()</span></tt></a> below to remove a directory.  This is identical to
the <a class="reference internal" href="#os.unlink" title="os.unlink"><tt class="xref py py-func docutils literal"><span class="pre">unlink()</span></tt></a> function documented below.  On Windows, attempting to
remove a file that is in use causes an exception to be raised; on Unix, the
directory entry is removed but the storage allocated to the file is not made
available until the original file is no longer in use.</p>
<p>Availability: Unix, Windows.</p>
</dd></dl>

<dl class="function">
<dt id="os.removedirs">
<tt class="descclassname">os.</tt><tt class="descname">removedirs</tt><big>(</big><em>path</em><big>)</big><a class="headerlink" href="#os.removedirs" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-16">Remove directories recursively.  Works like <a class="reference internal" href="#os.rmdir" title="os.rmdir"><tt class="xref py py-func docutils literal"><span class="pre">rmdir()</span></tt></a> except that, if the
leaf directory is successfully removed, <a class="reference internal" href="#os.removedirs" title="os.removedirs"><tt class="xref py py-func docutils literal"><span class="pre">removedirs()</span></tt></a>  tries to
successively remove every parent directory mentioned in  <em>path</em> until an error
is raised (which is ignored, because it generally means that a parent directory
is not empty). For example, <tt class="docutils literal"><span class="pre">os.removedirs('foo/bar/baz')</span></tt> will first remove
the directory <tt class="docutils literal"><span class="pre">'foo/bar/baz'</span></tt>, and then remove <tt class="docutils literal"><span class="pre">'foo/bar'</span></tt> and <tt class="docutils literal"><span class="pre">'foo'</span></tt> if
they are empty. Raises <a class="reference internal" href="exceptions.html#OSError" title="OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a> if the leaf directory could not be
successfully removed.</p>
</dd></dl>

<dl class="function">
<dt id="os.rename">
<tt class="descclassname">os.</tt><tt class="descname">rename</tt><big>(</big><em>src</em>, <em>dst</em><big>)</big><a class="headerlink" href="#os.rename" title="Permalink to this definition">¶</a></dt>
<dd><p>Rename the file or directory <em>src</em> to <em>dst</em>.  If <em>dst</em> is a directory,
<a class="reference internal" href="exceptions.html#OSError" title="OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a> will be raised.  On Unix, if <em>dst</em> exists and is a file, it will
be replaced silently if the user has permission.  The operation may fail on some
Unix flavors if <em>src</em> and <em>dst</em> are on different filesystems.  If successful,
the renaming will be an atomic operation (this is a POSIX requirement).  On
Windows, if <em>dst</em> already exists, <a class="reference internal" href="exceptions.html#OSError" title="OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a> will be raised even if it is a
file; there may be no way to implement an atomic rename when <em>dst</em> names an
existing file.</p>
<p>Availability: Unix, Windows.</p>
</dd></dl>

<dl class="function">
<dt id="os.renames">
<tt class="descclassname">os.</tt><tt class="descname">renames</tt><big>(</big><em>old</em>, <em>new</em><big>)</big><a class="headerlink" href="#os.renames" title="Permalink to this definition">¶</a></dt>
<dd><p>Recursive directory or file renaming function. Works like <a class="reference internal" href="#os.rename" title="os.rename"><tt class="xref py py-func docutils literal"><span class="pre">rename()</span></tt></a>, except
creation of any intermediate directories needed to make the new pathname good is
attempted first. After the rename, directories corresponding to rightmost path
segments of the old name will be pruned away using <a class="reference internal" href="#os.removedirs" title="os.removedirs"><tt class="xref py py-func docutils literal"><span class="pre">removedirs()</span></tt></a>.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">This function can fail with the new directory structure made if you lack
permissions needed to remove the leaf directory or file.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.rmdir">
<tt class="descclassname">os.</tt><tt class="descname">rmdir</tt><big>(</big><em>path</em><big>)</big><a class="headerlink" href="#os.rmdir" title="Permalink to this definition">¶</a></dt>
<dd><p>Remove (delete) the directory <em>path</em>.  Only works when the directory is
empty, otherwise, <a class="reference internal" href="exceptions.html#OSError" title="OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a> is raised.  In order to remove whole
directory trees, <a class="reference internal" href="shutil.html#shutil.rmtree" title="shutil.rmtree"><tt class="xref py py-func docutils literal"><span class="pre">shutil.rmtree()</span></tt></a> can be used.</p>
<p>Availability: Unix, Windows.</p>
</dd></dl>

<dl class="function">
<dt id="os.stat">
<tt class="descclassname">os.</tt><tt class="descname">stat</tt><big>(</big><em>path</em><big>)</big><a class="headerlink" href="#os.stat" title="Permalink to this definition">¶</a></dt>
<dd><p>Perform the equivalent of a <tt class="xref c c-func docutils literal"><span class="pre">stat()</span></tt> system call on the given path.
(This function follows symlinks; to stat a symlink use <a class="reference internal" href="#os.lstat" title="os.lstat"><tt class="xref py py-func docutils literal"><span class="pre">lstat()</span></tt></a>.)</p>
<p>The return value is an object whose attributes correspond to the members
of the <tt class="xref c c-type docutils literal"><span class="pre">stat</span></tt> structure, namely:</p>
<ul class="simple">
<li><tt class="xref py py-attr docutils literal"><span class="pre">st_mode</span></tt> - protection bits,</li>
<li><tt class="xref py py-attr docutils literal"><span class="pre">st_ino</span></tt> - inode number,</li>
<li><tt class="xref py py-attr docutils literal"><span class="pre">st_dev</span></tt> - device,</li>
<li><tt class="xref py py-attr docutils literal"><span class="pre">st_nlink</span></tt> - number of hard links,</li>
<li><tt class="xref py py-attr docutils literal"><span class="pre">st_uid</span></tt> - user id of owner,</li>
<li><tt class="xref py py-attr docutils literal"><span class="pre">st_gid</span></tt> - group id of owner,</li>
<li><tt class="xref py py-attr docutils literal"><span class="pre">st_size</span></tt> - size of file, in bytes,</li>
<li><tt class="xref py py-attr docutils literal"><span class="pre">st_atime</span></tt> - time of most recent access,</li>
<li><tt class="xref py py-attr docutils literal"><span class="pre">st_mtime</span></tt> - time of most recent content modification,</li>
<li><tt class="xref py py-attr docutils literal"><span class="pre">st_ctime</span></tt> - platform dependent; time of most recent metadata change on
Unix, or the time of creation on Windows)</li>
</ul>
<p>On some Unix systems (such as Linux), the following attributes may also be
available:</p>
<ul class="simple">
<li><tt class="xref py py-attr docutils literal"><span class="pre">st_blocks</span></tt> - number of blocks allocated for file</li>
<li><tt class="xref py py-attr docutils literal"><span class="pre">st_blksize</span></tt> - filesystem blocksize</li>
<li><tt class="xref py py-attr docutils literal"><span class="pre">st_rdev</span></tt> - type of device if an inode device</li>
<li><tt class="xref py py-attr docutils literal"><span class="pre">st_flags</span></tt> - user defined flags for file</li>
</ul>
<p>On other Unix systems (such as FreeBSD), the following attributes may be
available (but may be only filled out if root tries to use them):</p>
<ul class="simple">
<li><tt class="xref py py-attr docutils literal"><span class="pre">st_gen</span></tt> - file generation number</li>
<li><tt class="xref py py-attr docutils literal"><span class="pre">st_birthtime</span></tt> - time of file creation</li>
</ul>
<p>On Mac OS systems, the following attributes may also be available:</p>
<ul class="simple">
<li><tt class="xref py py-attr docutils literal"><span class="pre">st_rsize</span></tt></li>
<li><tt class="xref py py-attr docutils literal"><span class="pre">st_creator</span></tt></li>
<li><tt class="xref py py-attr docutils literal"><span class="pre">st_type</span></tt></li>
</ul>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">The exact meaning and resolution of the <tt class="xref py py-attr docutils literal"><span class="pre">st_atime</span></tt>,
<tt class="xref py py-attr docutils literal"><span class="pre">st_mtime</span></tt>, and <tt class="xref py py-attr docutils literal"><span class="pre">st_ctime</span></tt> attributes depend on the operating
system and the file system. For example, on Windows systems using the FAT
or FAT32 file systems, <tt class="xref py py-attr docutils literal"><span class="pre">st_mtime</span></tt> has 2-second resolution, and
<tt class="xref py py-attr docutils literal"><span class="pre">st_atime</span></tt> has only 1-day resolution.  See your operating system
documentation for details.</p>
</div>
<p>For backward compatibility, the return value of <a class="reference internal" href="#os.stat" title="os.stat"><tt class="xref py py-func docutils literal"><span class="pre">stat()</span></tt></a> is also accessible
as a tuple of at least 10 integers giving the most important (and portable)
members of the <tt class="xref c c-type docutils literal"><span class="pre">stat</span></tt> structure, in the order <tt class="xref py py-attr docutils literal"><span class="pre">st_mode</span></tt>,
<tt class="xref py py-attr docutils literal"><span class="pre">st_ino</span></tt>, <tt class="xref py py-attr docutils literal"><span class="pre">st_dev</span></tt>, <tt class="xref py py-attr docutils literal"><span class="pre">st_nlink</span></tt>, <tt class="xref py py-attr docutils literal"><span class="pre">st_uid</span></tt>,
<tt class="xref py py-attr docutils literal"><span class="pre">st_gid</span></tt>, <tt class="xref py py-attr docutils literal"><span class="pre">st_size</span></tt>, <tt class="xref py py-attr docutils literal"><span class="pre">st_atime</span></tt>, <tt class="xref py py-attr docutils literal"><span class="pre">st_mtime</span></tt>,
<tt class="xref py py-attr docutils literal"><span class="pre">st_ctime</span></tt>. More items may be added at the end by some implementations.</p>
<p id="index-17">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()."><tt class="xref py py-mod docutils literal"><span class="pre">stat</span></tt></a> defines functions and constants that are useful
for extracting information from a <tt class="xref c c-type docutils literal"><span class="pre">stat</span></tt> structure. (On Windows, some
items are filled with dummy values.)</p>
<p>Example:</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">os</span>
<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="s">&#39;somefile.txt&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">statinfo</span>
<span class="go">posix.stat_result(st_mode=33188, st_ino=7876932, st_dev=234881026,</span>
<span class="go">st_nlink=1, st_uid=501, st_gid=501, st_size=264, st_atime=1297230295,</span>
<span class="go">st_mtime=1297230027, st_ctime=1297230027)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">statinfo</span><span class="o">.</span><span class="n">st_size</span>
<span class="go">264</span>
</pre></div>
</div>
<p>Availability: Unix, Windows.</p>
</dd></dl>

<dl class="function">
<dt id="os.stat_float_times">
<tt class="descclassname">os.</tt><tt class="descname">stat_float_times</tt><big>(</big><span class="optional">[</span><em>newvalue</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#os.stat_float_times" title="Permalink to this definition">¶</a></dt>
<dd><p>Determine whether <tt class="xref py py-class docutils literal"><span class="pre">stat_result</span></tt> represents time stamps as float objects.
If <em>newvalue</em> is <tt class="xref docutils literal"><span class="pre">True</span></tt>, future calls to <a class="reference internal" href="#os.stat" title="os.stat"><tt class="xref py py-func docutils literal"><span class="pre">stat()</span></tt></a> return floats, if it is
<tt class="xref docutils literal"><span class="pre">False</span></tt>, future calls return ints. If <em>newvalue</em> is omitted, return the
current setting.</p>
<p>For compatibility with older Python versions, accessing <tt class="xref py py-class docutils literal"><span class="pre">stat_result</span></tt> as
a tuple always returns integers.</p>
<p>Python now returns float values by default. Applications which do not work
correctly with floating point time stamps can use this function to restore the
old behaviour.</p>
<p>The resolution of the timestamps (that is the smallest possible fraction)
depends on the system. Some systems only support second resolution; on these
systems, the fraction will always be zero.</p>
<p>It is recommended that this setting is only changed at program startup time in
the <em>__main__</em> module; libraries should never change this setting. If an
application uses a library that works incorrectly if floating point time stamps
are processed, this application should turn the feature off until the library
has been corrected.</p>
</dd></dl>

<dl class="function">
<dt id="os.statvfs">
<tt class="descclassname">os.</tt><tt class="descname">statvfs</tt><big>(</big><em>path</em><big>)</big><a class="headerlink" href="#os.statvfs" title="Permalink to this definition">¶</a></dt>
<dd><p>Perform a <tt class="xref c c-func docutils literal"><span class="pre">statvfs()</span></tt> system call on the given path.  The return value is
an object whose attributes describe the filesystem on the given path, and
correspond to the members of the <tt class="xref c c-type docutils literal"><span class="pre">statvfs</span></tt> structure, namely:
<tt class="xref py py-attr docutils literal"><span class="pre">f_bsize</span></tt>, <tt class="xref py py-attr docutils literal"><span class="pre">f_frsize</span></tt>, <tt class="xref py py-attr docutils literal"><span class="pre">f_blocks</span></tt>, <tt class="xref py py-attr docutils literal"><span class="pre">f_bfree</span></tt>,
<tt class="xref py py-attr docutils literal"><span class="pre">f_bavail</span></tt>, <tt class="xref py py-attr docutils literal"><span class="pre">f_files</span></tt>, <tt class="xref py py-attr docutils literal"><span class="pre">f_ffree</span></tt>, <tt class="xref py py-attr docutils literal"><span class="pre">f_favail</span></tt>,
<tt class="xref py py-attr docutils literal"><span class="pre">f_flag</span></tt>, <tt class="xref py py-attr docutils literal"><span class="pre">f_namemax</span></tt>.</p>
<p>Two module-level constants are defined for the <tt class="xref py py-attr docutils literal"><span class="pre">f_flag</span></tt> attribute&#8217;s
bit-flags: if <tt class="xref py py-const docutils literal"><span class="pre">ST_RDONLY</span></tt> is set, the filesystem is mounted
read-only, and if <tt class="xref py py-const docutils literal"><span class="pre">ST_NOSUID</span></tt> is set, the semantics of
setuid/setgid bits are disabled or not supported.</p>
<p class="versionchanged">
<span class="versionmodified">Changed in version 3.2: </span>The <tt class="xref py py-const docutils literal"><span class="pre">ST_RDONLY</span></tt> and <tt class="xref py py-const docutils literal"><span class="pre">ST_NOSUID</span></tt> constants were added.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.symlink">
<tt class="descclassname">os.</tt><tt class="descname">symlink</tt><big>(</big><em>source</em>, <em>link_name</em><big>)</big><a class="headerlink" href="#os.symlink" title="Permalink to this definition">¶</a></dt>
<dt>
<tt class="descclassname">os.</tt><tt class="descname">symlink</tt><big>(</big><em>source</em>, <em>link_name</em>, <em>target_is_directory=False</em><big>)</big></dt>
<dd><p>Create a symbolic link pointing to <em>source</em> named <em>link_name</em>.</p>
<p>On Windows, symlink version takes an additional optional parameter,
<em>target_is_directory</em>, which defaults to <tt class="xref docutils literal"><span class="pre">False</span></tt>.</p>
<p>On Windows, a symlink represents a file or a directory, and does not morph to
the target dynamically.  For this reason, when creating a symlink on Windows,
if the target is not already present, the symlink will default to being a
file symlink.  If <em>target_is_directory</em> is set to <tt class="xref docutils literal"><span class="pre">True</span></tt>, the symlink will
be created as a directory symlink.  This parameter is ignored if the target
exists (and the symlink is created with the same type as the target).</p>
<p>Symbolic link support was introduced in Windows 6.0 (Vista).  <a class="reference internal" href="#os.symlink" title="os.symlink"><tt class="xref py py-func docutils literal"><span class="pre">symlink()</span></tt></a>
will raise a <a class="reference internal" href="exceptions.html#NotImplementedError" title="NotImplementedError"><tt class="xref py py-exc docutils literal"><span class="pre">NotImplementedError</span></tt></a> on Windows versions earlier than 6.0.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p>The <em>SeCreateSymbolicLinkPrivilege</em> is required in order to successfully
create symlinks. This privilege is not typically granted to regular
users but is available to accounts which can escalate privileges to the
administrator level. Either obtaining the privilege or running your
application as an administrator are ways to successfully create symlinks.</p>
<p class="last"><a class="reference internal" href="exceptions.html#OSError" title="OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a> is raised when the function is called by an unprivileged
user.</p>
</div>
<p>Availability: Unix, Windows.</p>
<p class="versionchanged">
<span class="versionmodified">Changed in version 3.2: </span>Added support for Windows 6.0 (Vista) symbolic links.</p>
</dd></dl>

<dl class="function">
<dt id="os.unlink">
<tt class="descclassname">os.</tt><tt class="descname">unlink</tt><big>(</big><em>path</em><big>)</big><a class="headerlink" href="#os.unlink" title="Permalink to this definition">¶</a></dt>
<dd><p>Remove (delete) the file <em>path</em>.  This is the same function as
<a class="reference internal" href="#os.remove" title="os.remove"><tt class="xref py py-func docutils literal"><span class="pre">remove()</span></tt></a>; the <a class="reference internal" href="#os.unlink" title="os.unlink"><tt class="xref py py-func docutils literal"><span class="pre">unlink()</span></tt></a> name is its traditional Unix
name.</p>
<p>Availability: Unix, Windows.</p>
</dd></dl>

<dl class="function">
<dt id="os.utime">
<tt class="descclassname">os.</tt><tt class="descname">utime</tt><big>(</big><em>path</em>, <em>times</em><big>)</big><a class="headerlink" href="#os.utime" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the access and modified times of the file specified by <em>path</em>. If <em>times</em>
is <tt class="xref docutils literal"><span class="pre">None</span></tt>, then the file&#8217;s access and modified times are set to the current
time. (The effect is similar to running the Unix program <strong class="program">touch</strong> on
the path.)  Otherwise, <em>times</em> must be a 2-tuple of numbers, of the form
<tt class="docutils literal"><span class="pre">(atime,</span> <span class="pre">mtime)</span></tt> which is used to set the access and modified times,
respectively. Whether a directory can be given for <em>path</em> depends on whether
the operating system implements directories as files (for example, Windows
does not).  Note that the exact times you set here may not be returned by a
subsequent <a class="reference internal" href="#os.stat" title="os.stat"><tt class="xref py py-func docutils literal"><span class="pre">stat()</span></tt></a> call, depending on the resolution with which your
operating system records access and modification times; see <a class="reference internal" href="#os.stat" title="os.stat"><tt class="xref py py-func docutils literal"><span class="pre">stat()</span></tt></a>.</p>
<p>Availability: Unix, Windows.</p>
</dd></dl>

<dl class="function">
<dt id="os.walk">
<tt class="descclassname">os.</tt><tt class="descname">walk</tt><big>(</big><em>top</em>, <em>topdown=True</em>, <em>onerror=None</em>, <em>followlinks=False</em><big>)</big><a class="headerlink" href="#os.walk" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-18">Generate the file names in a directory tree by walking the tree
either top-down or bottom-up. For each directory in the tree rooted at directory
<em>top</em> (including <em>top</em> itself), it yields a 3-tuple <tt class="docutils literal"><span class="pre">(dirpath,</span> <span class="pre">dirnames,</span>
<span class="pre">filenames)</span></tt>.</p>
<p><em>dirpath</em> is a string, the path to the directory.  <em>dirnames</em> is a list of the
names of the subdirectories in <em>dirpath</em> (excluding <tt class="docutils literal"><span class="pre">'.'</span></tt> and <tt class="docutils literal"><span class="pre">'..'</span></tt>).
<em>filenames</em> is a list of the names of the non-directory files in <em>dirpath</em>.
Note that the names in the lists contain no path components.  To get a full path
(which begins with <em>top</em>) to a file or directory in <em>dirpath</em>, do
<tt class="docutils literal"><span class="pre">os.path.join(dirpath,</span> <span class="pre">name)</span></tt>.</p>
<p>If optional argument <em>topdown</em> is <tt class="xref docutils literal"><span class="pre">True</span></tt> or not specified, the triple for a
directory is generated before the triples for any of its subdirectories
(directories are generated top-down).  If <em>topdown</em> is <tt class="xref docutils literal"><span class="pre">False</span></tt>, the triple for a
directory is generated after the triples for all of its subdirectories
(directories are generated bottom-up).</p>
<p>When <em>topdown</em> is <tt class="xref docutils literal"><span class="pre">True</span></tt>, the caller can modify the <em>dirnames</em> list in-place
(perhaps using <a class="reference internal" href="../reference/simple_stmts.html#del"><tt class="xref std std-keyword docutils literal"><span class="pre">del</span></tt></a> or slice assignment), and <a class="reference internal" href="#os.walk" title="os.walk"><tt class="xref py py-func docutils literal"><span class="pre">walk()</span></tt></a> will only
recurse into the subdirectories whose names remain in <em>dirnames</em>; this can be
used to prune the search, impose a specific order of visiting, or even to inform
<a class="reference internal" href="#os.walk" title="os.walk"><tt class="xref py py-func docutils literal"><span class="pre">walk()</span></tt></a> about directories the caller creates or renames before it resumes
<a class="reference internal" href="#os.walk" title="os.walk"><tt class="xref py py-func docutils literal"><span class="pre">walk()</span></tt></a> again.  Modifying <em>dirnames</em> when <em>topdown</em> is <tt class="xref docutils literal"><span class="pre">False</span></tt> is
ineffective, because in bottom-up mode the directories in <em>dirnames</em> are
generated before <em>dirpath</em> itself is generated.</p>
<p>By default errors from the <a class="reference internal" href="#os.listdir" title="os.listdir"><tt class="xref py py-func docutils literal"><span class="pre">listdir()</span></tt></a> call are ignored.  If optional
argument <em>onerror</em> is specified, it should be a function; it will be called with
one argument, an <a class="reference internal" href="exceptions.html#OSError" title="OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a> instance.  It can report the error to continue
with the walk, or raise the exception to abort the walk.  Note that the filename
is available as the <tt class="docutils literal"><span class="pre">filename</span></tt> attribute of the exception object.</p>
<p>By default, <a class="reference internal" href="#os.walk" title="os.walk"><tt class="xref py py-func docutils literal"><span class="pre">walk()</span></tt></a> will not walk down into symbolic links that resolve to
directories. Set <em>followlinks</em> to <tt class="xref docutils literal"><span class="pre">True</span></tt> to visit directories pointed to by
symlinks, on systems that support them.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Be aware that setting <em>followlinks</em> to <tt class="xref docutils literal"><span class="pre">True</span></tt> can lead to infinite recursion if a
link points to a parent directory of itself. <a class="reference internal" href="#os.walk" title="os.walk"><tt class="xref py py-func docutils literal"><span class="pre">walk()</span></tt></a> does not keep track of
the directories it visited already.</p>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">If you pass a relative pathname, don&#8217;t change the current working directory
between resumptions of <a class="reference internal" href="#os.walk" title="os.walk"><tt class="xref py py-func docutils literal"><span class="pre">walk()</span></tt></a>.  <a class="reference internal" href="#os.walk" title="os.walk"><tt class="xref py py-func docutils literal"><span class="pre">walk()</span></tt></a> never changes the current
directory, and assumes that its caller doesn&#8217;t either.</p>
</div>
<p>This example displays the number of bytes taken by non-directory files in each
directory under the starting directory, except that it doesn&#8217;t look under any
CVS subdirectory:</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">os</span>
<span class="kn">from</span> <span class="nn">os.path</span> <span class="k">import</span> <span class="n">join</span><span class="p">,</span> <span class="n">getsize</span>
<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="s">&#39;python/Lib/email&#39;</span><span class="p">):</span>
    <span class="nb">print</span><span class="p">(</span><span class="n">root</span><span class="p">,</span> <span class="s">&quot;consumes&quot;</span><span class="p">,</span> <span class="n">end</span><span class="o">=</span><span class="s">&quot; &quot;</span><span class="p">)</span>
    <span class="nb">print</span><span class="p">(</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> <span class="n">end</span><span class="o">=</span><span class="s">&quot; &quot;</span><span class="p">)</span>
    <span class="nb">print</span><span class="p">(</span><span class="s">&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="s">&quot;non-directory files&quot;</span><span class="p">)</span>
    <span class="k">if</span> <span class="s">&#39;CVS&#39;</span> <span class="ow">in</span> <span class="n">dirs</span><span class="p">:</span>
        <span class="n">dirs</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="s">&#39;CVS&#39;</span><span class="p">)</span>  <span class="c"># don&#39;t visit CVS directories</span>
</pre></div>
</div>
<p>In the next example, walking the tree bottom-up is essential: <a class="reference internal" href="#os.rmdir" title="os.rmdir"><tt class="xref py py-func docutils literal"><span class="pre">rmdir()</span></tt></a>
doesn&#8217;t allow deleting a directory before the directory is empty:</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="c"># Delete everything reachable from the directory named in &quot;top&quot;,</span>
<span class="c"># assuming there are no symbolic links.</span>
<span class="c"># CAUTION:  This is dangerous!  For example, if top == &#39;/&#39;, it</span>
<span class="c"># could delete all your disk files.</span>
<span class="kn">import</span> <span class="nn">os</span>
<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="k">False</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>
        <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>
    <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">dirs</span><span class="p">:</span>
        <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>
</pre></div>
</div>
</dd></dl>

</div>
<div class="section" id="process-management">
<span id="os-process"></span><h2>15.1.6. Process Management<a class="headerlink" href="#process-management" title="Permalink to this headline">¶</a></h2>
<p>These functions may be used to create and manage processes.</p>
<p>The various <tt class="xref py py-func docutils literal"><span class="pre">exec*()</span></tt> functions take a list of arguments for the new
program loaded into the process.  In each case, the first of these arguments is
passed to the new program as its own name rather than as an argument a user may
have typed on a command line.  For the C programmer, this is the <tt class="docutils literal"><span class="pre">argv[0]</span></tt>
passed to a program&#8217;s <tt class="xref c c-func docutils literal"><span class="pre">main()</span></tt>.  For example, <tt class="docutils literal"><span class="pre">os.execv('/bin/echo',</span>
<span class="pre">['foo',</span> <span class="pre">'bar'])</span></tt> will only print <tt class="docutils literal"><span class="pre">bar</span></tt> on standard output; <tt class="docutils literal"><span class="pre">foo</span></tt> will seem
to be ignored.</p>
<dl class="function">
<dt id="os.abort">
<tt class="descclassname">os.</tt><tt class="descname">abort</tt><big>(</big><big>)</big><a class="headerlink" href="#os.abort" title="Permalink to this definition">¶</a></dt>
<dd><p>Generate a <tt class="xref py py-const docutils literal"><span class="pre">SIGABRT</span></tt> signal to the current process.  On Unix, the default
behavior is to produce a core dump; on Windows, the process immediately returns
an exit code of <tt class="docutils literal"><span class="pre">3</span></tt>.  Be aware that calling this function will not call the
Python signal handler registered for <tt class="xref py py-const docutils literal"><span class="pre">SIGABRT</span></tt> with
<a class="reference internal" href="signal.html#signal.signal" title="signal.signal"><tt class="xref py py-func docutils literal"><span class="pre">signal.signal()</span></tt></a>.</p>
<p>Availability: Unix, Windows.</p>
</dd></dl>

<dl class="function">
<dt id="os.execl">
<tt class="descclassname">os.</tt><tt class="descname">execl</tt><big>(</big><em>path</em>, <em>arg0</em>, <em>arg1</em>, <em>...</em><big>)</big><a class="headerlink" href="#os.execl" title="Permalink to this definition">¶</a></dt>
<dt id="os.execle">
<tt class="descclassname">os.</tt><tt class="descname">execle</tt><big>(</big><em>path</em>, <em>arg0</em>, <em>arg1</em>, <em>...</em>, <em>env</em><big>)</big><a class="headerlink" href="#os.execle" title="Permalink to this definition">¶</a></dt>
<dt id="os.execlp">
<tt class="descclassname">os.</tt><tt class="descname">execlp</tt><big>(</big><em>file</em>, <em>arg0</em>, <em>arg1</em>, <em>...</em><big>)</big><a class="headerlink" href="#os.execlp" title="Permalink to this definition">¶</a></dt>
<dt id="os.execlpe">
<tt class="descclassname">os.</tt><tt class="descname">execlpe</tt><big>(</big><em>file</em>, <em>arg0</em>, <em>arg1</em>, <em>...</em>, <em>env</em><big>)</big><a class="headerlink" href="#os.execlpe" title="Permalink to this definition">¶</a></dt>
<dt id="os.execv">
<tt class="descclassname">os.</tt><tt class="descname">execv</tt><big>(</big><em>path</em>, <em>args</em><big>)</big><a class="headerlink" href="#os.execv" title="Permalink to this definition">¶</a></dt>
<dt id="os.execve">
<tt class="descclassname">os.</tt><tt class="descname">execve</tt><big>(</big><em>path</em>, <em>args</em>, <em>env</em><big>)</big><a class="headerlink" href="#os.execve" title="Permalink to this definition">¶</a></dt>
<dt id="os.execvp">
<tt class="descclassname">os.</tt><tt class="descname">execvp</tt><big>(</big><em>file</em>, <em>args</em><big>)</big><a class="headerlink" href="#os.execvp" title="Permalink to this definition">¶</a></dt>
<dt id="os.execvpe">
<tt class="descclassname">os.</tt><tt class="descname">execvpe</tt><big>(</big><em>file</em>, <em>args</em>, <em>env</em><big>)</big><a class="headerlink" href="#os.execvpe" title="Permalink to this definition">¶</a></dt>
<dd><p>These functions all execute a new program, replacing the current process; they
do not return.  On Unix, the new executable is loaded into the current process,
and will have the same process id as the caller.  Errors will be reported as
<a class="reference internal" href="exceptions.html#OSError" title="OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a> exceptions.</p>
<p>The current process is replaced immediately. Open file objects and
descriptors are not flushed, so if there may be data buffered
on these open files, you should flush them using
<tt class="xref py py-func docutils literal"><span class="pre">sys.stdout.flush()</span></tt> or <a class="reference internal" href="#os.fsync" title="os.fsync"><tt class="xref py py-func docutils literal"><span class="pre">os.fsync()</span></tt></a> before calling an
<tt class="xref py py-func docutils literal"><span class="pre">exec*()</span></tt> function.</p>
<p>The &#8220;l&#8221; and &#8220;v&#8221; variants of the <tt class="xref py py-func docutils literal"><span class="pre">exec*()</span></tt> functions differ in how
command-line arguments are passed.  The &#8220;l&#8221; variants are perhaps the easiest
to work with if the number of parameters is fixed when the code is written; the
individual parameters simply become additional parameters to the <tt class="xref py py-func docutils literal"><span class="pre">execl*()</span></tt>
functions.  The &#8220;v&#8221; variants are good when the number of parameters is
variable, with the arguments being passed in a list or tuple as the <em>args</em>
parameter.  In either case, the arguments to the child process should start with
the name of the command being run, but this is not enforced.</p>
<p>The variants which include a &#8220;p&#8221; near the end (<a class="reference internal" href="#os.execlp" title="os.execlp"><tt class="xref py py-func docutils literal"><span class="pre">execlp()</span></tt></a>,
<a class="reference internal" href="#os.execlpe" title="os.execlpe"><tt class="xref py py-func docutils literal"><span class="pre">execlpe()</span></tt></a>, <a class="reference internal" href="#os.execvp" title="os.execvp"><tt class="xref py py-func docutils literal"><span class="pre">execvp()</span></tt></a>, and <a class="reference internal" href="#os.execvpe" title="os.execvpe"><tt class="xref py py-func docutils literal"><span class="pre">execvpe()</span></tt></a>) will use the
<span class="target" id="index-19"></span><tt class="xref std std-envvar docutils literal"><span class="pre">PATH</span></tt> environment variable to locate the program <em>file</em>.  When the
environment is being replaced (using one of the <tt class="xref py py-func docutils literal"><span class="pre">exec*e()</span></tt> variants,
discussed in the next paragraph), the new environment is used as the source of
the <span class="target" id="index-20"></span><tt class="xref std std-envvar docutils literal"><span class="pre">PATH</span></tt> variable. The other variants, <a class="reference internal" href="#os.execl" title="os.execl"><tt class="xref py py-func docutils literal"><span class="pre">execl()</span></tt></a>, <a class="reference internal" href="#os.execle" title="os.execle"><tt class="xref py py-func docutils literal"><span class="pre">execle()</span></tt></a>,
<a class="reference internal" href="#os.execv" title="os.execv"><tt class="xref py py-func docutils literal"><span class="pre">execv()</span></tt></a>, and <a class="reference internal" href="#os.execve" title="os.execve"><tt class="xref py py-func docutils literal"><span class="pre">execve()</span></tt></a>, will not use the <span class="target" id="index-21"></span><tt class="xref std std-envvar docutils literal"><span class="pre">PATH</span></tt> variable to
locate the executable; <em>path</em> must contain an appropriate absolute or relative
path.</p>
<p>For <a class="reference internal" href="#os.execle" title="os.execle"><tt class="xref py py-func docutils literal"><span class="pre">execle()</span></tt></a>, <a class="reference internal" href="#os.execlpe" title="os.execlpe"><tt class="xref py py-func docutils literal"><span class="pre">execlpe()</span></tt></a>, <a class="reference internal" href="#os.execve" title="os.execve"><tt class="xref py py-func docutils literal"><span class="pre">execve()</span></tt></a>, and <a class="reference internal" href="#os.execvpe" title="os.execvpe"><tt class="xref py py-func docutils literal"><span class="pre">execvpe()</span></tt></a> (note
that these all end in &#8220;e&#8221;), the <em>env</em> parameter must be a mapping which is
used to define the environment variables for the new process (these are used
instead of the current process&#8217; environment); the functions <a class="reference internal" href="#os.execl" title="os.execl"><tt class="xref py py-func docutils literal"><span class="pre">execl()</span></tt></a>,
<a class="reference internal" href="#os.execlp" title="os.execlp"><tt class="xref py py-func docutils literal"><span class="pre">execlp()</span></tt></a>, <a class="reference internal" href="#os.execv" title="os.execv"><tt class="xref py py-func docutils literal"><span class="pre">execv()</span></tt></a>, and <a class="reference internal" href="#os.execvp" title="os.execvp"><tt class="xref py py-func docutils literal"><span class="pre">execvp()</span></tt></a> all cause the new process to
inherit the environment of the current process.</p>
<p>Availability: Unix, Windows.</p>
</dd></dl>

<dl class="function">
<dt id="os._exit">
<tt class="descclassname">os.</tt><tt class="descname">_exit</tt><big>(</big><em>n</em><big>)</big><a class="headerlink" href="#os._exit" title="Permalink to this definition">¶</a></dt>
<dd><p>Exit the process with status <em>n</em>, without calling cleanup handlers, flushing
stdio buffers, etc.</p>
<p>Availability: Unix, Windows.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">The standard way to exit is <tt class="docutils literal"><span class="pre">sys.exit(n)</span></tt>.  <a class="reference internal" href="#os._exit" title="os._exit"><tt class="xref py py-func docutils literal"><span class="pre">_exit()</span></tt></a> should
normally only be used in the child process after a <a class="reference internal" href="#os.fork" title="os.fork"><tt class="xref py py-func docutils literal"><span class="pre">fork()</span></tt></a>.</p>
</div>
</dd></dl>

<p>The following exit codes are defined and can be used with <a class="reference internal" href="#os._exit" title="os._exit"><tt class="xref py py-func docutils literal"><span class="pre">_exit()</span></tt></a>,
although they are not required.  These are typically used for system programs
written in Python, such as a mail server&#8217;s external command delivery program.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Some of these may not be available on all Unix platforms, since there is some
variation.  These constants are defined where they are defined by the underlying
platform.</p>
</div>
<dl class="data">
<dt id="os.EX_OK">
<tt class="descclassname">os.</tt><tt class="descname">EX_OK</tt><a class="headerlink" href="#os.EX_OK" title="Permalink to this definition">¶</a></dt>
<dd><p>Exit code that means no error occurred.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="data">
<dt id="os.EX_USAGE">
<tt class="descclassname">os.</tt><tt class="descname">EX_USAGE</tt><a class="headerlink" href="#os.EX_USAGE" title="Permalink to this definition">¶</a></dt>
<dd><p>Exit code that means the command was used incorrectly, such as when the wrong
number of arguments are given.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="data">
<dt id="os.EX_DATAERR">
<tt class="descclassname">os.</tt><tt class="descname">EX_DATAERR</tt><a class="headerlink" href="#os.EX_DATAERR" title="Permalink to this definition">¶</a></dt>
<dd><p>Exit code that means the input data was incorrect.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="data">
<dt id="os.EX_NOINPUT">
<tt class="descclassname">os.</tt><tt class="descname">EX_NOINPUT</tt><a class="headerlink" href="#os.EX_NOINPUT" title="Permalink to this definition">¶</a></dt>
<dd><p>Exit code that means an input file did not exist or was not readable.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="data">
<dt id="os.EX_NOUSER">
<tt class="descclassname">os.</tt><tt class="descname">EX_NOUSER</tt><a class="headerlink" href="#os.EX_NOUSER" title="Permalink to this definition">¶</a></dt>
<dd><p>Exit code that means a specified user did not exist.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="data">
<dt id="os.EX_NOHOST">
<tt class="descclassname">os.</tt><tt class="descname">EX_NOHOST</tt><a class="headerlink" href="#os.EX_NOHOST" title="Permalink to this definition">¶</a></dt>
<dd><p>Exit code that means a specified host did not exist.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="data">
<dt id="os.EX_UNAVAILABLE">
<tt class="descclassname">os.</tt><tt class="descname">EX_UNAVAILABLE</tt><a class="headerlink" href="#os.EX_UNAVAILABLE" title="Permalink to this definition">¶</a></dt>
<dd><p>Exit code that means that a required service is unavailable.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="data">
<dt id="os.EX_SOFTWARE">
<tt class="descclassname">os.</tt><tt class="descname">EX_SOFTWARE</tt><a class="headerlink" href="#os.EX_SOFTWARE" title="Permalink to this definition">¶</a></dt>
<dd><p>Exit code that means an internal software error was detected.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="data">
<dt id="os.EX_OSERR">
<tt class="descclassname">os.</tt><tt class="descname">EX_OSERR</tt><a class="headerlink" href="#os.EX_OSERR" title="Permalink to this definition">¶</a></dt>
<dd><p>Exit code that means an operating system error was detected, such as the
inability to fork or create a pipe.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="data">
<dt id="os.EX_OSFILE">
<tt class="descclassname">os.</tt><tt class="descname">EX_OSFILE</tt><a class="headerlink" href="#os.EX_OSFILE" title="Permalink to this definition">¶</a></dt>
<dd><p>Exit code that means some system file did not exist, could not be opened, or had
some other kind of error.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="data">
<dt id="os.EX_CANTCREAT">
<tt class="descclassname">os.</tt><tt class="descname">EX_CANTCREAT</tt><a class="headerlink" href="#os.EX_CANTCREAT" title="Permalink to this definition">¶</a></dt>
<dd><p>Exit code that means a user specified output file could not be created.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="data">
<dt id="os.EX_IOERR">
<tt class="descclassname">os.</tt><tt class="descname">EX_IOERR</tt><a class="headerlink" href="#os.EX_IOERR" title="Permalink to this definition">¶</a></dt>
<dd><p>Exit code that means that an error occurred while doing I/O on some file.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="data">
<dt id="os.EX_TEMPFAIL">
<tt class="descclassname">os.</tt><tt class="descname">EX_TEMPFAIL</tt><a class="headerlink" href="#os.EX_TEMPFAIL" title="Permalink to this definition">¶</a></dt>
<dd><p>Exit code that means a temporary failure occurred.  This indicates something
that may not really be an error, such as a network connection that couldn&#8217;t be
made during a retryable operation.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="data">
<dt id="os.EX_PROTOCOL">
<tt class="descclassname">os.</tt><tt class="descname">EX_PROTOCOL</tt><a class="headerlink" href="#os.EX_PROTOCOL" title="Permalink to this definition">¶</a></dt>
<dd><p>Exit code that means that a protocol exchange was illegal, invalid, or not
understood.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="data">
<dt id="os.EX_NOPERM">
<tt class="descclassname">os.</tt><tt class="descname">EX_NOPERM</tt><a class="headerlink" href="#os.EX_NOPERM" title="Permalink to this definition">¶</a></dt>
<dd><p>Exit code that means that there were insufficient permissions to perform the
operation (but not intended for file system problems).</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="data">
<dt id="os.EX_CONFIG">
<tt class="descclassname">os.</tt><tt class="descname">EX_CONFIG</tt><a class="headerlink" href="#os.EX_CONFIG" title="Permalink to this definition">¶</a></dt>
<dd><p>Exit code that means that some kind of configuration error occurred.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="data">
<dt id="os.EX_NOTFOUND">
<tt class="descclassname">os.</tt><tt class="descname">EX_NOTFOUND</tt><a class="headerlink" href="#os.EX_NOTFOUND" title="Permalink to this definition">¶</a></dt>
<dd><p>Exit code that means something like &#8220;an entry was not found&#8221;.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.fork">
<tt class="descclassname">os.</tt><tt class="descname">fork</tt><big>(</big><big>)</big><a class="headerlink" href="#os.fork" title="Permalink to this definition">¶</a></dt>
<dd><p>Fork a child process.  Return <tt class="docutils literal"><span class="pre">0</span></tt> in the child and the child&#8217;s process id in the
parent.  If an error occurs <a class="reference internal" href="exceptions.html#OSError" title="OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a> is raised.</p>
<p>Note that some platforms including FreeBSD &lt;= 6.3, Cygwin and OS/2 EMX have
known issues when using fork() from a thread.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.forkpty">
<tt class="descclassname">os.</tt><tt class="descname">forkpty</tt><big>(</big><big>)</big><a class="headerlink" href="#os.forkpty" title="Permalink to this definition">¶</a></dt>
<dd><p>Fork a child process, using a new pseudo-terminal as the child&#8217;s controlling
terminal. Return a pair of <tt class="docutils literal"><span class="pre">(pid,</span> <span class="pre">fd)</span></tt>, where <em>pid</em> is <tt class="docutils literal"><span class="pre">0</span></tt> in the child, the
new child&#8217;s process id in the parent, and <em>fd</em> is the file descriptor of the
master end of the pseudo-terminal.  For a more portable approach, use the
<a class="reference internal" href="pty.html#module-pty" title="pty: Pseudo-Terminal Handling for Linux. (Linux)"><tt class="xref py py-mod docutils literal"><span class="pre">pty</span></tt></a> module.  If an error occurs <a class="reference internal" href="exceptions.html#OSError" title="OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a> is raised.</p>
<p>Availability: some flavors of Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.kill">
<tt class="descclassname">os.</tt><tt class="descname">kill</tt><big>(</big><em>pid</em>, <em>sig</em><big>)</big><a class="headerlink" href="#os.kill" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-22">Send signal <em>sig</em> to the process <em>pid</em>.  Constants for the specific signals
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."><tt class="xref py py-mod docutils literal"><span class="pre">signal</span></tt></a> module.</p>
<p>Windows: The <a class="reference internal" href="signal.html#signal.CTRL_C_EVENT" title="signal.CTRL_C_EVENT"><tt class="xref py py-data docutils literal"><span class="pre">signal.CTRL_C_EVENT</span></tt></a> and
<a class="reference internal" href="signal.html#signal.CTRL_BREAK_EVENT" title="signal.CTRL_BREAK_EVENT"><tt class="xref py py-data docutils literal"><span class="pre">signal.CTRL_BREAK_EVENT</span></tt></a> signals are special signals which can
only be sent to console processes which share a common console window,
e.g., some subprocesses. Any other value for <em>sig</em> will cause the process
to be unconditionally killed by the TerminateProcess API, and the exit code
will be set to <em>sig</em>. The Windows version of <a class="reference internal" href="#os.kill" title="os.kill"><tt class="xref py py-func docutils literal"><span class="pre">kill()</span></tt></a> additionally takes
process handles to be killed.</p>
<p class="versionadded">
<span class="versionmodified">New in version 3.2: </span>Windows support.</p>
</dd></dl>

<dl class="function">
<dt id="os.killpg">
<tt class="descclassname">os.</tt><tt class="descname">killpg</tt><big>(</big><em>pgid</em>, <em>sig</em><big>)</big><a class="headerlink" href="#os.killpg" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-23">Send the signal <em>sig</em> to the process group <em>pgid</em>.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.nice">
<tt class="descclassname">os.</tt><tt class="descname">nice</tt><big>(</big><em>increment</em><big>)</big><a class="headerlink" href="#os.nice" title="Permalink to this definition">¶</a></dt>
<dd><p>Add <em>increment</em> to the process&#8217;s &#8220;niceness&#8221;.  Return the new niceness.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.plock">
<tt class="descclassname">os.</tt><tt class="descname">plock</tt><big>(</big><em>op</em><big>)</big><a class="headerlink" href="#os.plock" title="Permalink to this definition">¶</a></dt>
<dd><p>Lock program segments into memory.  The value of <em>op</em> (defined in
<tt class="docutils literal"><span class="pre">&lt;sys/lock.h&gt;</span></tt>) determines which segments are locked.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt>
<tt class="descclassname">os.</tt><tt class="descname">popen</tt><big>(</big><em>...</em><big>)</big></dt>
<dd><p>Run child processes, returning opened pipes for communications.  These functions
are described in section <a class="reference internal" href="#os-newstreams"><em>File Object Creation</em></a>.</p>
</dd></dl>

<dl class="function">
<dt id="os.spawnl">
<tt class="descclassname">os.</tt><tt class="descname">spawnl</tt><big>(</big><em>mode</em>, <em>path</em>, <em>...</em><big>)</big><a class="headerlink" href="#os.spawnl" title="Permalink to this definition">¶</a></dt>
<dt id="os.spawnle">
<tt class="descclassname">os.</tt><tt class="descname">spawnle</tt><big>(</big><em>mode</em>, <em>path</em>, <em>...</em>, <em>env</em><big>)</big><a class="headerlink" href="#os.spawnle" title="Permalink to this definition">¶</a></dt>
<dt id="os.spawnlp">
<tt class="descclassname">os.</tt><tt class="descname">spawnlp</tt><big>(</big><em>mode</em>, <em>file</em>, <em>...</em><big>)</big><a class="headerlink" href="#os.spawnlp" title="Permalink to this definition">¶</a></dt>
<dt id="os.spawnlpe">
<tt class="descclassname">os.</tt><tt class="descname">spawnlpe</tt><big>(</big><em>mode</em>, <em>file</em>, <em>...</em>, <em>env</em><big>)</big><a class="headerlink" href="#os.spawnlpe" title="Permalink to this definition">¶</a></dt>
<dt id="os.spawnv">
<tt class="descclassname">os.</tt><tt class="descname">spawnv</tt><big>(</big><em>mode</em>, <em>path</em>, <em>args</em><big>)</big><a class="headerlink" href="#os.spawnv" title="Permalink to this definition">¶</a></dt>
<dt id="os.spawnve">
<tt class="descclassname">os.</tt><tt class="descname">spawnve</tt><big>(</big><em>mode</em>, <em>path</em>, <em>args</em>, <em>env</em><big>)</big><a class="headerlink" href="#os.spawnve" title="Permalink to this definition">¶</a></dt>
<dt id="os.spawnvp">
<tt class="descclassname">os.</tt><tt class="descname">spawnvp</tt><big>(</big><em>mode</em>, <em>file</em>, <em>args</em><big>)</big><a class="headerlink" href="#os.spawnvp" title="Permalink to this definition">¶</a></dt>
<dt id="os.spawnvpe">
<tt class="descclassname">os.</tt><tt class="descname">spawnvpe</tt><big>(</big><em>mode</em>, <em>file</em>, <em>args</em>, <em>env</em><big>)</big><a class="headerlink" href="#os.spawnvpe" title="Permalink to this definition">¶</a></dt>
<dd><p>Execute the program <em>path</em> in a new process.</p>
<p>(Note that the <a class="reference internal" href="subprocess.html#module-subprocess" title="subprocess: Subprocess management."><tt class="xref py py-mod docutils literal"><span class="pre">subprocess</span></tt></a> module provides more powerful facilities for
spawning new processes and retrieving their results; using that module is
preferable to using these functions.  Check especially the
<a class="reference internal" href="subprocess.html#subprocess-replacements"><em>Replacing Older Functions with the subprocess Module</em></a> section.)</p>
<p>If <em>mode</em> is <a class="reference internal" href="#os.P_NOWAIT" title="os.P_NOWAIT"><tt class="xref py py-const docutils literal"><span class="pre">P_NOWAIT</span></tt></a>, this function returns the process id of the new
process; if <em>mode</em> is <a class="reference internal" href="#os.P_WAIT" title="os.P_WAIT"><tt class="xref py py-const docutils literal"><span class="pre">P_WAIT</span></tt></a>, returns the process&#8217;s exit code if it
exits normally, or <tt class="docutils literal"><span class="pre">-signal</span></tt>, where <em>signal</em> is the signal that killed the
process.  On Windows, the process id will actually be the process handle, so can
be used with the <a class="reference internal" href="#os.waitpid" title="os.waitpid"><tt class="xref py py-func docutils literal"><span class="pre">waitpid()</span></tt></a> function.</p>
<p>The &#8220;l&#8221; and &#8220;v&#8221; variants of the <tt class="xref py py-func docutils literal"><span class="pre">spawn*()</span></tt> functions differ in how
command-line arguments are passed.  The &#8220;l&#8221; variants are perhaps the easiest
to work with if the number of parameters is fixed when the code is written; the
individual parameters simply become additional parameters to the
<tt class="xref py py-func docutils literal"><span class="pre">spawnl*()</span></tt> functions.  The &#8220;v&#8221; variants are good when the number of
parameters is variable, with the arguments being passed in a list or tuple as
the <em>args</em> parameter.  In either case, the arguments to the child process must
start with the name of the command being run.</p>
<p>The variants which include a second &#8220;p&#8221; near the end (<a class="reference internal" href="#os.spawnlp" title="os.spawnlp"><tt class="xref py py-func docutils literal"><span class="pre">spawnlp()</span></tt></a>,
<a class="reference internal" href="#os.spawnlpe" title="os.spawnlpe"><tt class="xref py py-func docutils literal"><span class="pre">spawnlpe()</span></tt></a>, <a class="reference internal" href="#os.spawnvp" title="os.spawnvp"><tt class="xref py py-func docutils literal"><span class="pre">spawnvp()</span></tt></a>, and <a class="reference internal" href="#os.spawnvpe" title="os.spawnvpe"><tt class="xref py py-func docutils literal"><span class="pre">spawnvpe()</span></tt></a>) will use the
<span class="target" id="index-24"></span><tt class="xref std std-envvar docutils literal"><span class="pre">PATH</span></tt> environment variable to locate the program <em>file</em>.  When the
environment is being replaced (using one of the <tt class="xref py py-func docutils literal"><span class="pre">spawn*e()</span></tt> variants,
discussed in the next paragraph), the new environment is used as the source of
the <span class="target" id="index-25"></span><tt class="xref std std-envvar docutils literal"><span class="pre">PATH</span></tt> variable.  The other variants, <a class="reference internal" href="#os.spawnl" title="os.spawnl"><tt class="xref py py-func docutils literal"><span class="pre">spawnl()</span></tt></a>,
<a class="reference internal" href="#os.spawnle" title="os.spawnle"><tt class="xref py py-func docutils literal"><span class="pre">spawnle()</span></tt></a>, <a class="reference internal" href="#os.spawnv" title="os.spawnv"><tt class="xref py py-func docutils literal"><span class="pre">spawnv()</span></tt></a>, and <a class="reference internal" href="#os.spawnve" title="os.spawnve"><tt class="xref py py-func docutils literal"><span class="pre">spawnve()</span></tt></a>, will not use the
<span class="target" id="index-26"></span><tt class="xref std std-envvar docutils literal"><span class="pre">PATH</span></tt> variable to locate the executable; <em>path</em> must contain an
appropriate absolute or relative path.</p>
<p>For <a class="reference internal" href="#os.spawnle" title="os.spawnle"><tt class="xref py py-func docutils literal"><span class="pre">spawnle()</span></tt></a>, <a class="reference internal" href="#os.spawnlpe" title="os.spawnlpe"><tt class="xref py py-func docutils literal"><span class="pre">spawnlpe()</span></tt></a>, <a class="reference internal" href="#os.spawnve" title="os.spawnve"><tt class="xref py py-func docutils literal"><span class="pre">spawnve()</span></tt></a>, and <a class="reference internal" href="#os.spawnvpe" title="os.spawnvpe"><tt class="xref py py-func docutils literal"><span class="pre">spawnvpe()</span></tt></a>
(note that these all end in &#8220;e&#8221;), the <em>env</em> parameter must be a mapping
which is used to define the environment variables for the new process (they are
used instead of the current process&#8217; environment); the functions
<a class="reference internal" href="#os.spawnl" title="os.spawnl"><tt class="xref py py-func docutils literal"><span class="pre">spawnl()</span></tt></a>, <a class="reference internal" href="#os.spawnlp" title="os.spawnlp"><tt class="xref py py-func docutils literal"><span class="pre">spawnlp()</span></tt></a>, <a class="reference internal" href="#os.spawnv" title="os.spawnv"><tt class="xref py py-func docutils literal"><span class="pre">spawnv()</span></tt></a>, and <a class="reference internal" href="#os.spawnvp" title="os.spawnvp"><tt class="xref py py-func docutils literal"><span class="pre">spawnvp()</span></tt></a> all cause
the new process to inherit the environment of the current process.  Note that
keys and values in the <em>env</em> dictionary must be strings; invalid keys or
values will cause the function to fail, with a return value of <tt class="docutils literal"><span class="pre">127</span></tt>.</p>
<p>As an example, the following calls to <a class="reference internal" href="#os.spawnlp" title="os.spawnlp"><tt class="xref py py-func docutils literal"><span class="pre">spawnlp()</span></tt></a> and <a class="reference internal" href="#os.spawnvpe" title="os.spawnvpe"><tt class="xref py py-func docutils literal"><span class="pre">spawnvpe()</span></tt></a> are
equivalent:</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">os</span>
<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="s">&#39;cp&#39;</span><span class="p">,</span> <span class="s">&#39;cp&#39;</span><span class="p">,</span> <span class="s">&#39;index.html&#39;</span><span class="p">,</span> <span class="s">&#39;/dev/null&#39;</span><span class="p">)</span>

<span class="n">L</span> <span class="o">=</span> <span class="p">[</span><span class="s">&#39;cp&#39;</span><span class="p">,</span> <span class="s">&#39;index.html&#39;</span><span class="p">,</span> <span class="s">&#39;/dev/null&#39;</span><span class="p">]</span>
<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="s">&#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>
</pre></div>
</div>
<p>Availability: Unix, Windows.  <a class="reference internal" href="#os.spawnlp" title="os.spawnlp"><tt class="xref py py-func docutils literal"><span class="pre">spawnlp()</span></tt></a>, <a class="reference internal" href="#os.spawnlpe" title="os.spawnlpe"><tt class="xref py py-func docutils literal"><span class="pre">spawnlpe()</span></tt></a>, <a class="reference internal" href="#os.spawnvp" title="os.spawnvp"><tt class="xref py py-func docutils literal"><span class="pre">spawnvp()</span></tt></a>
and <a class="reference internal" href="#os.spawnvpe" title="os.spawnvpe"><tt class="xref py py-func docutils literal"><span class="pre">spawnvpe()</span></tt></a> are not available on Windows.  <a class="reference internal" href="#os.spawnle" title="os.spawnle"><tt class="xref py py-func docutils literal"><span class="pre">spawnle()</span></tt></a> and
<a class="reference internal" href="#os.spawnve" title="os.spawnve"><tt class="xref py py-func docutils literal"><span class="pre">spawnve()</span></tt></a> are not thread-safe on Windows; we advise you to use the
<a class="reference internal" href="subprocess.html#module-subprocess" title="subprocess: Subprocess management."><tt class="xref py py-mod docutils literal"><span class="pre">subprocess</span></tt></a> module instead.</p>
</dd></dl>

<dl class="data">
<dt id="os.P_NOWAIT">
<tt class="descclassname">os.</tt><tt class="descname">P_NOWAIT</tt><a class="headerlink" href="#os.P_NOWAIT" title="Permalink to this definition">¶</a></dt>
<dt id="os.P_NOWAITO">
<tt class="descclassname">os.</tt><tt class="descname">P_NOWAITO</tt><a class="headerlink" href="#os.P_NOWAITO" title="Permalink to this definition">¶</a></dt>
<dd><p>Possible values for the <em>mode</em> parameter to the <tt class="xref py py-func docutils literal"><span class="pre">spawn*()</span></tt> family of
functions.  If either of these values is given, the <tt class="xref py py-func docutils literal"><span class="pre">spawn*()</span></tt> functions
will return as soon as the new process has been created, with the process id as
the return value.</p>
<p>Availability: Unix, Windows.</p>
</dd></dl>

<dl class="data">
<dt id="os.P_WAIT">
<tt class="descclassname">os.</tt><tt class="descname">P_WAIT</tt><a class="headerlink" href="#os.P_WAIT" title="Permalink to this definition">¶</a></dt>
<dd><p>Possible value for the <em>mode</em> parameter to the <tt class="xref py py-func docutils literal"><span class="pre">spawn*()</span></tt> family of
functions.  If this is given as <em>mode</em>, the <tt class="xref py py-func docutils literal"><span class="pre">spawn*()</span></tt> functions will not
return until the new process has run to completion and will return the exit code
of the process the run is successful, or <tt class="docutils literal"><span class="pre">-signal</span></tt> if a signal kills the
process.</p>
<p>Availability: Unix, Windows.</p>
</dd></dl>

<dl class="data">
<dt id="os.P_DETACH">
<tt class="descclassname">os.</tt><tt class="descname">P_DETACH</tt><a class="headerlink" href="#os.P_DETACH" title="Permalink to this definition">¶</a></dt>
<dt id="os.P_OVERLAY">
<tt class="descclassname">os.</tt><tt class="descname">P_OVERLAY</tt><a class="headerlink" href="#os.P_OVERLAY" title="Permalink to this definition">¶</a></dt>
<dd><p>Possible values for the <em>mode</em> parameter to the <tt class="xref py py-func docutils literal"><span class="pre">spawn*()</span></tt> family of
functions.  These are less portable than those listed above. <a class="reference internal" href="#os.P_DETACH" title="os.P_DETACH"><tt class="xref py py-const docutils literal"><span class="pre">P_DETACH</span></tt></a>
is similar to <a class="reference internal" href="#os.P_NOWAIT" title="os.P_NOWAIT"><tt class="xref py py-const docutils literal"><span class="pre">P_NOWAIT</span></tt></a>, but the new process is detached from the
console of the calling process. If <a class="reference internal" href="#os.P_OVERLAY" title="os.P_OVERLAY"><tt class="xref py py-const docutils literal"><span class="pre">P_OVERLAY</span></tt></a> is used, the current
process will be replaced; the <tt class="xref py py-func docutils literal"><span class="pre">spawn*()</span></tt> function will not return.</p>
<p>Availability: Windows.</p>
</dd></dl>

<dl class="function">
<dt id="os.startfile">
<tt class="descclassname">os.</tt><tt class="descname">startfile</tt><big>(</big><em>path</em><span class="optional">[</span>, <em>operation</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#os.startfile" title="Permalink to this definition">¶</a></dt>
<dd><p>Start a file with its associated application.</p>
<p>When <em>operation</em> is not specified or <tt class="docutils literal"><span class="pre">'open'</span></tt>, this acts like double-clicking
the file in Windows Explorer, or giving the file name as an argument to the
<strong class="program">start</strong> command from the interactive command shell: the file is opened
with whatever application (if any) its extension is associated.</p>
<p>When another <em>operation</em> is given, it must be a &#8220;command verb&#8221; that specifies
what should be done with the file. Common verbs documented by Microsoft are
<tt class="docutils literal"><span class="pre">'print'</span></tt> and  <tt class="docutils literal"><span class="pre">'edit'</span></tt> (to be used on files) as well as <tt class="docutils literal"><span class="pre">'explore'</span></tt> and
<tt class="docutils literal"><span class="pre">'find'</span></tt> (to be used on directories).</p>
<p><a class="reference internal" href="#os.startfile" title="os.startfile"><tt class="xref py py-func docutils literal"><span class="pre">startfile()</span></tt></a> returns as soon as the associated application is launched.
There is no option to wait for the application to close, and no way to retrieve
the application&#8217;s exit status.  The <em>path</em> parameter is relative to the current
directory.  If you want to use an absolute path, make sure the first character
is not a slash (<tt class="docutils literal"><span class="pre">'/'</span></tt>); the underlying Win32 <tt class="xref c c-func docutils literal"><span class="pre">ShellExecute()</span></tt> function
doesn&#8217;t work if it is.  Use the <a class="reference internal" href="os.path.html#os.path.normpath" title="os.path.normpath"><tt class="xref py py-func docutils literal"><span class="pre">os.path.normpath()</span></tt></a> function to ensure that
the path is properly encoded for Win32.</p>
<p>Availability: Windows.</p>
</dd></dl>

<dl class="function">
<dt id="os.system">
<tt class="descclassname">os.</tt><tt class="descname">system</tt><big>(</big><em>command</em><big>)</big><a class="headerlink" href="#os.system" title="Permalink to this definition">¶</a></dt>
<dd><p>Execute the command (a string) in a subshell.  This is implemented by calling
the Standard C function <tt class="xref c c-func docutils literal"><span class="pre">system()</span></tt>, and has the same limitations.
Changes to <a class="reference internal" href="sys.html#sys.stdin" title="sys.stdin"><tt class="xref py py-data docutils literal"><span class="pre">sys.stdin</span></tt></a>, etc. are not reflected in the environment of
the executed command. If <em>command</em> generates any output, it will be sent to
the interpreter standard output stream.</p>
<p>On Unix, the return value is the exit status of the process encoded in the
format specified for <a class="reference internal" href="#os.wait" title="os.wait"><tt class="xref py py-func docutils literal"><span class="pre">wait()</span></tt></a>.  Note that POSIX does not specify the
meaning of the return value of the C <tt class="xref c c-func docutils literal"><span class="pre">system()</span></tt> function, so the return
value of the Python function is system-dependent.</p>
<p>On Windows, the return value is that returned by the system shell after
running <em>command</em>.  The shell is given by the Windows environment variable
<span class="target" id="index-27"></span><tt class="xref std std-envvar docutils literal"><span class="pre">COMSPEC</span></tt>: it is usually <strong class="program">cmd.exe</strong>, which returns the exit
status of the command run; on systems using a non-native shell, consult your
shell documentation.</p>
<p>The <a class="reference internal" href="subprocess.html#module-subprocess" title="subprocess: Subprocess management."><tt class="xref py py-mod docutils literal"><span class="pre">subprocess</span></tt></a> module provides more powerful facilities for spawning
new processes and retrieving their results; using that module is preferable
to using this function.  See the <a class="reference internal" href="subprocess.html#subprocess-replacements"><em>Replacing Older Functions with the subprocess Module</em></a> section in
the <a class="reference internal" href="subprocess.html#module-subprocess" title="subprocess: Subprocess management."><tt class="xref py py-mod docutils literal"><span class="pre">subprocess</span></tt></a> documentation for some helpful recipes.</p>
<p>Availability: Unix, Windows.</p>
</dd></dl>

<dl class="function">
<dt id="os.times">
<tt class="descclassname">os.</tt><tt class="descname">times</tt><big>(</big><big>)</big><a class="headerlink" href="#os.times" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a 5-tuple of floating point numbers indicating accumulated (processor
or other) times, in seconds.  The items are: user time, system time,
children&#8217;s user time, children&#8217;s system time, and elapsed real time since a
fixed point in the past, in that order.  See the Unix manual page
<em class="manpage">times(2)</em> or the corresponding Windows Platform API documentation.
On Windows, only the first two items are filled, the others are zero.</p>
<p>Availability: Unix, Windows</p>
</dd></dl>

<dl class="function">
<dt id="os.wait">
<tt class="descclassname">os.</tt><tt class="descname">wait</tt><big>(</big><big>)</big><a class="headerlink" href="#os.wait" title="Permalink to this definition">¶</a></dt>
<dd><p>Wait for completion of a child process, and return a tuple containing its pid
and exit status indication: a 16-bit number, whose low byte is the signal number
that killed the process, and whose high byte is the exit status (if the signal
number is zero); the high bit of the low byte is set if a core file was
produced.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.waitpid">
<tt class="descclassname">os.</tt><tt class="descname">waitpid</tt><big>(</big><em>pid</em>, <em>options</em><big>)</big><a class="headerlink" href="#os.waitpid" title="Permalink to this definition">¶</a></dt>
<dd><p>The details of this function differ on Unix and Windows.</p>
<p>On Unix: Wait for completion of a child process given by process id <em>pid</em>, and
return a tuple containing its process id and exit status indication (encoded as
for <a class="reference internal" href="#os.wait" title="os.wait"><tt class="xref py py-func docutils literal"><span class="pre">wait()</span></tt></a>).  The semantics of the call are affected by the value of the
integer <em>options</em>, which should be <tt class="docutils literal"><span class="pre">0</span></tt> for normal operation.</p>
<p>If <em>pid</em> is greater than <tt class="docutils literal"><span class="pre">0</span></tt>, <a class="reference internal" href="#os.waitpid" title="os.waitpid"><tt class="xref py py-func docutils literal"><span class="pre">waitpid()</span></tt></a> requests status information for
that specific process.  If <em>pid</em> is <tt class="docutils literal"><span class="pre">0</span></tt>, the request is for the status of any
child in the process group of the current process.  If <em>pid</em> is <tt class="docutils literal"><span class="pre">-1</span></tt>, the
request pertains to any child of the current process.  If <em>pid</em> is less than
<tt class="docutils literal"><span class="pre">-1</span></tt>, status is requested for any process in the process group <tt class="docutils literal"><span class="pre">-pid</span></tt> (the
absolute value of <em>pid</em>).</p>
<p>An <a class="reference internal" href="exceptions.html#OSError" title="OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a> is raised with the value of errno when the syscall
returns -1.</p>
<p>On Windows: Wait for completion of a process given by process handle <em>pid</em>, and
return a tuple containing <em>pid</em>, and its exit status shifted left by 8 bits
(shifting makes cross-platform use of the function easier). A <em>pid</em> less than or
equal to <tt class="docutils literal"><span class="pre">0</span></tt> has no special meaning on Windows, and raises an exception. The
value of integer <em>options</em> has no effect. <em>pid</em> can refer to any process whose
id is known, not necessarily a child process. The <tt class="xref py py-func docutils literal"><span class="pre">spawn()</span></tt> functions called
with <a class="reference internal" href="#os.P_NOWAIT" title="os.P_NOWAIT"><tt class="xref py py-const docutils literal"><span class="pre">P_NOWAIT</span></tt></a> return suitable process handles.</p>
</dd></dl>

<dl class="function">
<dt id="os.wait3">
<tt class="descclassname">os.</tt><tt class="descname">wait3</tt><big>(</big><span class="optional">[</span><em>options</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#os.wait3" title="Permalink to this definition">¶</a></dt>
<dd><p>Similar to <a class="reference internal" href="#os.waitpid" title="os.waitpid"><tt class="xref py py-func docutils literal"><span class="pre">waitpid()</span></tt></a>, except no process id argument is given and a
3-element tuple containing the child&#8217;s process id, exit status indication, and
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)"><tt class="xref py py-mod docutils literal"><span class="pre">resource</span></tt></a>.<tt class="xref py py-func docutils literal"><span class="pre">getrusage()</span></tt> for details on resource usage information.  The option
argument is the same as that provided to <a class="reference internal" href="#os.waitpid" title="os.waitpid"><tt class="xref py py-func docutils literal"><span class="pre">waitpid()</span></tt></a> and <a class="reference internal" href="#os.wait4" title="os.wait4"><tt class="xref py py-func docutils literal"><span class="pre">wait4()</span></tt></a>.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.wait4">
<tt class="descclassname">os.</tt><tt class="descname">wait4</tt><big>(</big><em>pid</em>, <em>options</em><big>)</big><a class="headerlink" href="#os.wait4" title="Permalink to this definition">¶</a></dt>
<dd><p>Similar to <a class="reference internal" href="#os.waitpid" title="os.waitpid"><tt class="xref py py-func docutils literal"><span class="pre">waitpid()</span></tt></a>, except a 3-element tuple, containing the child&#8217;s
process id, exit status indication, and 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)"><tt class="xref py py-mod docutils literal"><span class="pre">resource</span></tt></a>.<tt class="xref py py-func docutils literal"><span class="pre">getrusage()</span></tt> for details on resource usage
information.  The arguments to <a class="reference internal" href="#os.wait4" title="os.wait4"><tt class="xref py py-func docutils literal"><span class="pre">wait4()</span></tt></a> are the same as those provided to
<a class="reference internal" href="#os.waitpid" title="os.waitpid"><tt class="xref py py-func docutils literal"><span class="pre">waitpid()</span></tt></a>.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="data">
<dt id="os.WNOHANG">
<tt class="descclassname">os.</tt><tt class="descname">WNOHANG</tt><a class="headerlink" href="#os.WNOHANG" title="Permalink to this definition">¶</a></dt>
<dd><p>The option for <a class="reference internal" href="#os.waitpid" title="os.waitpid"><tt class="xref py py-func docutils literal"><span class="pre">waitpid()</span></tt></a> to return immediately if no child process status
is available immediately. The function returns <tt class="docutils literal"><span class="pre">(0,</span> <span class="pre">0)</span></tt> in this case.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="data">
<dt id="os.WCONTINUED">
<tt class="descclassname">os.</tt><tt class="descname">WCONTINUED</tt><a class="headerlink" href="#os.WCONTINUED" title="Permalink to this definition">¶</a></dt>
<dd><p>This option causes child processes to be reported if they have been continued
from a job control stop since their status was last reported.</p>
<p>Availability: Some Unix systems.</p>
</dd></dl>

<dl class="data">
<dt id="os.WUNTRACED">
<tt class="descclassname">os.</tt><tt class="descname">WUNTRACED</tt><a class="headerlink" href="#os.WUNTRACED" title="Permalink to this definition">¶</a></dt>
<dd><p>This option causes child processes to be reported if they have been stopped but
their current state has not been reported since they were stopped.</p>
<p>Availability: Unix.</p>
</dd></dl>

<p>The following functions take a process status code as returned by
<a class="reference internal" href="#os.system" title="os.system"><tt class="xref py py-func docutils literal"><span class="pre">system()</span></tt></a>, <a class="reference internal" href="#os.wait" title="os.wait"><tt class="xref py py-func docutils literal"><span class="pre">wait()</span></tt></a>, or <a class="reference internal" href="#os.waitpid" title="os.waitpid"><tt class="xref py py-func docutils literal"><span class="pre">waitpid()</span></tt></a> as a parameter.  They may be
used to determine the disposition of a process.</p>
<dl class="function">
<dt id="os.WCOREDUMP">
<tt class="descclassname">os.</tt><tt class="descname">WCOREDUMP</tt><big>(</big><em>status</em><big>)</big><a class="headerlink" href="#os.WCOREDUMP" title="Permalink to this definition">¶</a></dt>
<dd><p>Return <tt class="xref docutils literal"><span class="pre">True</span></tt> if a core dump was generated for the process, otherwise
return <tt class="xref docutils literal"><span class="pre">False</span></tt>.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.WIFCONTINUED">
<tt class="descclassname">os.</tt><tt class="descname">WIFCONTINUED</tt><big>(</big><em>status</em><big>)</big><a class="headerlink" href="#os.WIFCONTINUED" title="Permalink to this definition">¶</a></dt>
<dd><p>Return <tt class="xref docutils literal"><span class="pre">True</span></tt> if the process has been continued from a job control stop,
otherwise return <tt class="xref docutils literal"><span class="pre">False</span></tt>.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.WIFSTOPPED">
<tt class="descclassname">os.</tt><tt class="descname">WIFSTOPPED</tt><big>(</big><em>status</em><big>)</big><a class="headerlink" href="#os.WIFSTOPPED" title="Permalink to this definition">¶</a></dt>
<dd><p>Return <tt class="xref docutils literal"><span class="pre">True</span></tt> if the process has been stopped, otherwise return
<tt class="xref docutils literal"><span class="pre">False</span></tt>.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.WIFSIGNALED">
<tt class="descclassname">os.</tt><tt class="descname">WIFSIGNALED</tt><big>(</big><em>status</em><big>)</big><a class="headerlink" href="#os.WIFSIGNALED" title="Permalink to this definition">¶</a></dt>
<dd><p>Return <tt class="xref docutils literal"><span class="pre">True</span></tt> if the process exited due to a signal, otherwise return
<tt class="xref docutils literal"><span class="pre">False</span></tt>.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.WIFEXITED">
<tt class="descclassname">os.</tt><tt class="descname">WIFEXITED</tt><big>(</big><em>status</em><big>)</big><a class="headerlink" href="#os.WIFEXITED" title="Permalink to this definition">¶</a></dt>
<dd><p>Return <tt class="xref docutils literal"><span class="pre">True</span></tt> if the process exited using the <em class="manpage">exit(2)</em> system call,
otherwise return <tt class="xref docutils literal"><span class="pre">False</span></tt>.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.WEXITSTATUS">
<tt class="descclassname">os.</tt><tt class="descname">WEXITSTATUS</tt><big>(</big><em>status</em><big>)</big><a class="headerlink" href="#os.WEXITSTATUS" title="Permalink to this definition">¶</a></dt>
<dd><p>If <tt class="docutils literal"><span class="pre">WIFEXITED(status)</span></tt> is true, return the integer parameter to the
<em class="manpage">exit(2)</em> system call.  Otherwise, the return value is meaningless.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.WSTOPSIG">
<tt class="descclassname">os.</tt><tt class="descname">WSTOPSIG</tt><big>(</big><em>status</em><big>)</big><a class="headerlink" href="#os.WSTOPSIG" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the signal which caused the process to stop.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.WTERMSIG">
<tt class="descclassname">os.</tt><tt class="descname">WTERMSIG</tt><big>(</big><em>status</em><big>)</big><a class="headerlink" href="#os.WTERMSIG" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the signal which caused the process to exit.</p>
<p>Availability: Unix.</p>
</dd></dl>

</div>
<div class="section" id="miscellaneous-system-information">
<span id="os-path"></span><h2>15.1.7. Miscellaneous System Information<a class="headerlink" href="#miscellaneous-system-information" title="Permalink to this headline">¶</a></h2>
<dl class="function">
<dt id="os.confstr">
<tt class="descclassname">os.</tt><tt class="descname">confstr</tt><big>(</big><em>name</em><big>)</big><a class="headerlink" href="#os.confstr" title="Permalink to this definition">¶</a></dt>
<dd><p>Return string-valued system configuration values. <em>name</em> specifies the
configuration value to retrieve; it may be a string which is the name of a
defined system value; these names are specified in a number of standards (POSIX,
Unix 95, Unix 98, and others).  Some platforms define additional names as well.
The names known to the host operating system are given as the keys of the
<tt class="docutils literal"><span class="pre">confstr_names</span></tt> dictionary.  For configuration variables not included in that
mapping, passing an integer for <em>name</em> is also accepted.</p>
<p>If the configuration value specified by <em>name</em> isn&#8217;t defined, <tt class="xref docutils literal"><span class="pre">None</span></tt> is
returned.</p>
<p>If <em>name</em> is a string and is not known, <a class="reference internal" href="exceptions.html#ValueError" title="ValueError"><tt class="xref py py-exc docutils literal"><span class="pre">ValueError</span></tt></a> is raised.  If a
specific value for <em>name</em> is not supported by the host system, even if it is
included in <tt class="docutils literal"><span class="pre">confstr_names</span></tt>, an <a class="reference internal" href="exceptions.html#OSError" title="OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a> is raised with
<a class="reference internal" href="errno.html#errno.EINVAL" title="errno.EINVAL"><tt class="xref py py-const docutils literal"><span class="pre">errno.EINVAL</span></tt></a> for the error number.</p>
<p>Availability: Unix</p>
</dd></dl>

<dl class="data">
<dt id="os.confstr_names">
<tt class="descclassname">os.</tt><tt class="descname">confstr_names</tt><a class="headerlink" href="#os.confstr_names" title="Permalink to this definition">¶</a></dt>
<dd><p>Dictionary mapping names accepted by <a class="reference internal" href="#os.confstr" title="os.confstr"><tt class="xref py py-func docutils literal"><span class="pre">confstr()</span></tt></a> to the integer values
defined for those names by the host operating system. This can be used to
determine the set of names known to the system.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.getloadavg">
<tt class="descclassname">os.</tt><tt class="descname">getloadavg</tt><big>(</big><big>)</big><a class="headerlink" href="#os.getloadavg" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the number of processes in the system run queue averaged over the last
1, 5, and 15 minutes or raises <a class="reference internal" href="exceptions.html#OSError" title="OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a> if the load average was
unobtainable.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.sysconf">
<tt class="descclassname">os.</tt><tt class="descname">sysconf</tt><big>(</big><em>name</em><big>)</big><a class="headerlink" href="#os.sysconf" title="Permalink to this definition">¶</a></dt>
<dd><p>Return integer-valued system configuration values. If the configuration value
specified by <em>name</em> isn&#8217;t defined, <tt class="docutils literal"><span class="pre">-1</span></tt> is returned.  The comments regarding
the <em>name</em> parameter for <a class="reference internal" href="#os.confstr" title="os.confstr"><tt class="xref py py-func docutils literal"><span class="pre">confstr()</span></tt></a> apply here as well; the dictionary that
provides information on the known names is given by <tt class="docutils literal"><span class="pre">sysconf_names</span></tt>.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="data">
<dt id="os.sysconf_names">
<tt class="descclassname">os.</tt><tt class="descname">sysconf_names</tt><a class="headerlink" href="#os.sysconf_names" title="Permalink to this definition">¶</a></dt>
<dd><p>Dictionary mapping names accepted by <a class="reference internal" href="#os.sysconf" title="os.sysconf"><tt class="xref py py-func docutils literal"><span class="pre">sysconf()</span></tt></a> to the integer values
defined for those names by the host operating system. This can be used to
determine the set of names known to the system.</p>
<p>Availability: Unix.</p>
</dd></dl>

<p>The following data values are used to support path manipulation operations.  These
are defined for all platforms.</p>
<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."><tt class="xref py py-mod docutils literal"><span class="pre">os.path</span></tt></a> module.</p>
<dl class="data">
<dt id="os.curdir">
<tt class="descclassname">os.</tt><tt class="descname">curdir</tt><a class="headerlink" href="#os.curdir" title="Permalink to this definition">¶</a></dt>
<dd><p>The constant string used by the operating system to refer to the current
directory. This is <tt class="docutils literal"><span class="pre">'.'</span></tt> for Windows and POSIX. Also available via
<a class="reference internal" href="os.path.html#module-os.path" title="os.path: Operations on pathnames."><tt class="xref py py-mod docutils literal"><span class="pre">os.path</span></tt></a>.</p>
</dd></dl>

<dl class="data">
<dt id="os.pardir">
<tt class="descclassname">os.</tt><tt class="descname">pardir</tt><a class="headerlink" href="#os.pardir" title="Permalink to this definition">¶</a></dt>
<dd><p>The constant string used by the operating system to refer to the parent
directory. This is <tt class="docutils literal"><span class="pre">'..'</span></tt> for Windows and POSIX. Also available via
<a class="reference internal" href="os.path.html#module-os.path" title="os.path: Operations on pathnames."><tt class="xref py py-mod docutils literal"><span class="pre">os.path</span></tt></a>.</p>
</dd></dl>

<dl class="data">
<dt id="os.sep">
<tt class="descclassname">os.</tt><tt class="descname">sep</tt><a class="headerlink" href="#os.sep" title="Permalink to this definition">¶</a></dt>
<dd><p>The character used by the operating system to separate pathname components.
This is <tt class="docutils literal"><span class="pre">'/'</span></tt> for POSIX and <tt class="docutils literal"><span class="pre">'\\'</span></tt> for Windows.  Note that knowing this
is not sufficient to be able to parse or concatenate pathnames &#8212; use
<a class="reference internal" href="os.path.html#os.path.split" title="os.path.split"><tt class="xref py py-func docutils literal"><span class="pre">os.path.split()</span></tt></a> and <a class="reference internal" href="os.path.html#os.path.join" title="os.path.join"><tt class="xref py py-func docutils literal"><span class="pre">os.path.join()</span></tt></a> &#8212; but it is occasionally
useful. Also available via <a class="reference internal" href="os.path.html#module-os.path" title="os.path: Operations on pathnames."><tt class="xref py py-mod docutils literal"><span class="pre">os.path</span></tt></a>.</p>
</dd></dl>

<dl class="data">
<dt id="os.altsep">
<tt class="descclassname">os.</tt><tt class="descname">altsep</tt><a class="headerlink" href="#os.altsep" title="Permalink to this definition">¶</a></dt>
<dd><p>An alternative character used by the operating system to separate pathname
components, or <tt class="xref docutils literal"><span class="pre">None</span></tt> if only one separator character exists.  This is set to
<tt class="docutils literal"><span class="pre">'/'</span></tt> on Windows systems where <tt class="docutils literal"><span class="pre">sep</span></tt> is a backslash. Also available via
<a class="reference internal" href="os.path.html#module-os.path" title="os.path: Operations on pathnames."><tt class="xref py py-mod docutils literal"><span class="pre">os.path</span></tt></a>.</p>
</dd></dl>

<dl class="data">
<dt id="os.extsep">
<tt class="descclassname">os.</tt><tt class="descname">extsep</tt><a class="headerlink" href="#os.extsep" title="Permalink to this definition">¶</a></dt>
<dd><p>The character which separates the base filename from the extension; for example,
the <tt class="docutils literal"><span class="pre">'.'</span></tt> in <tt class="file docutils literal"><span class="pre">os.py</span></tt>. Also available via <a class="reference internal" href="os.path.html#module-os.path" title="os.path: Operations on pathnames."><tt class="xref py py-mod docutils literal"><span class="pre">os.path</span></tt></a>.</p>
</dd></dl>

<dl class="data">
<dt id="os.pathsep">
<tt class="descclassname">os.</tt><tt class="descname">pathsep</tt><a class="headerlink" href="#os.pathsep" title="Permalink to this definition">¶</a></dt>
<dd><p>The character conventionally used by the operating system to separate search
path components (as in <span class="target" id="index-28"></span><tt class="xref std std-envvar docutils literal"><span class="pre">PATH</span></tt>), such as <tt class="docutils literal"><span class="pre">':'</span></tt> for POSIX or <tt class="docutils literal"><span class="pre">';'</span></tt> for
Windows. Also available via <a class="reference internal" href="os.path.html#module-os.path" title="os.path: Operations on pathnames."><tt class="xref py py-mod docutils literal"><span class="pre">os.path</span></tt></a>.</p>
</dd></dl>

<dl class="data">
<dt id="os.defpath">
<tt class="descclassname">os.</tt><tt class="descname">defpath</tt><a class="headerlink" href="#os.defpath" title="Permalink to this definition">¶</a></dt>
<dd><p>The default search path used by <tt class="xref py py-func docutils literal"><span class="pre">exec*p*()</span></tt> and <tt class="xref py py-func docutils literal"><span class="pre">spawn*p*()</span></tt> if the
environment doesn&#8217;t have a <tt class="docutils literal"><span class="pre">'PATH'</span></tt> key. Also available via <a class="reference internal" href="os.path.html#module-os.path" title="os.path: Operations on pathnames."><tt class="xref py py-mod docutils literal"><span class="pre">os.path</span></tt></a>.</p>
</dd></dl>

<dl class="data">
<dt id="os.linesep">
<tt class="descclassname">os.</tt><tt class="descname">linesep</tt><a class="headerlink" href="#os.linesep" title="Permalink to this definition">¶</a></dt>
<dd><p>The string used to separate (or, rather, terminate) lines on the current
platform.  This may be a single character, such as <tt class="docutils literal"><span class="pre">'\n'</span></tt> for POSIX, or
multiple characters, for example, <tt class="docutils literal"><span class="pre">'\r\n'</span></tt> for Windows. Do not use
<em>os.linesep</em> as a line terminator when writing files opened in text mode (the
default); use a single <tt class="docutils literal"><span class="pre">'\n'</span></tt> instead, on all platforms.</p>
</dd></dl>

<dl class="data">
<dt id="os.devnull">
<tt class="descclassname">os.</tt><tt class="descname">devnull</tt><a class="headerlink" href="#os.devnull" title="Permalink to this definition">¶</a></dt>
<dd><p>The file path of the null device. For example: <tt class="docutils literal"><span class="pre">'/dev/null'</span></tt> for
POSIX, <tt class="docutils literal"><span class="pre">'nul'</span></tt> for Windows.  Also available via <a class="reference internal" href="os.path.html#module-os.path" title="os.path: Operations on pathnames."><tt class="xref py py-mod docutils literal"><span class="pre">os.path</span></tt></a>.</p>
</dd></dl>

</div>
<div class="section" id="miscellaneous-functions">
<span id="os-miscfunc"></span><h2>15.1.8. Miscellaneous Functions<a class="headerlink" href="#miscellaneous-functions" title="Permalink to this headline">¶</a></h2>
<dl class="function">
<dt id="os.urandom">
<tt class="descclassname">os.</tt><tt class="descname">urandom</tt><big>(</big><em>n</em><big>)</big><a class="headerlink" href="#os.urandom" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a string of <em>n</em> random bytes suitable for cryptographic use.</p>
<p>This function returns random bytes from an OS-specific randomness source.  The
returned data should be unpredictable enough for cryptographic applications,
though its exact quality depends on the OS implementation.  On a UNIX-like
system this will query /dev/urandom, and on Windows it will use CryptGenRandom.
If a randomness source is not found, <a class="reference internal" href="exceptions.html#NotImplementedError" title="NotImplementedError"><tt class="xref py py-exc docutils literal"><span class="pre">NotImplementedError</span></tt></a> will be raised.</p>
</dd></dl>

</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../contents.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">15.1. <tt class="docutils literal"><span class="pre">os</span></tt> &#8212; Miscellaneous operating system interfaces</a><ul>
<li><a class="reference internal" href="#file-names-command-line-arguments-and-environment-variables">15.1.1. File Names, Command Line Arguments, and Environment Variables</a></li>
<li><a class="reference internal" href="#process-parameters">15.1.2. Process Parameters</a></li>
<li><a class="reference internal" href="#file-object-creation">15.1.3. File Object Creation</a></li>
<li><a class="reference internal" href="#file-descriptor-operations">15.1.4. File Descriptor Operations</a><ul>
<li><a class="reference internal" href="#open-flag-constants">15.1.4.1. <tt class="docutils literal"><span class="pre">open()</span></tt> flag constants</a></li>
</ul>
</li>
<li><a class="reference internal" href="#files-and-directories">15.1.5. Files and Directories</a></li>
<li><a class="reference internal" href="#process-management">15.1.6. Process Management</a></li>
<li><a class="reference internal" href="#miscellaneous-system-information">15.1.7. Miscellaneous System Information</a></li>
<li><a class="reference internal" href="#miscellaneous-functions">15.1.8. Miscellaneous Functions</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="allos.html"
                        title="previous chapter">15. Generic Operating System Services</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="io.html"
                        title="next chapter">15.2. <tt class="docutils literal docutils literal"><span class="pre">io</span></tt> &#8212; Core tools for working with streams</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
  <li><a href="../bugs.html">Report a Bug</a></li>
  <li><a href="../_sources/library/os.txt"
         rel="nofollow">Show Source</a></li>
</ul>

<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" size="18" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="io.html" title="15.2. io — Core tools for working with streams"
             >next</a> |</li>
        <li class="right" >
          <a href="allos.html" title="15. Generic Operating System Services"
             >previous</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="../index.html">Python v3.2.2 documentation</a> &raquo;</li>

          <li><a href="index.html" >The Python Standard Library</a> &raquo;</li>
          <li><a href="allos.html" >15. Generic Operating System Services</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
    &copy; <a href="../copyright.html">Copyright</a> 1990-2011, Python Software Foundation.
    <br />
    The Python Software Foundation is a non-profit corporation.  
    <a href="http://www.python.org/psf/donations/">Please donate.</a>
    <br />
    Last updated on Sep 04, 2011.
    <a href="../bugs.html">Found a bug</a>?
    <br />
    Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.7.
    </div>

  </body>
</html>