<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!--Converted with LaTeX2HTML 98.2 beta6 (August 14th, 1998)
original version by:  Nikos Drakos, CBLU, University of Leeds
* revised and updated by:  Marcus Hennecke, Ross Moore, Herb Swan
* with significant contributions from:
  Jens Lippmann, Marek Rouchal, Martin Wilck and others -->
<HTML>
<HEAD>
<TITLE>6.1 os --
Miscellaneous OS interfaces</TITLE>
<META NAME="description" CONTENT="6.1 os --
Miscellaneous OS interfaces">
<META NAME="keywords" CONTENT="lib">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<LINK REL="STYLESHEET" HREF="lib.css">
<LINK REL="next" HREF="module-os.path.html">
<LINK REL="previous" HREF="allos.html">
<LINK REL="up" HREF="allos.html">
<LINK REL="next" HREF="os-procinfo.html">
</HEAD>
<BODY bgcolor="#ffffff">
<div class=navigation>
<table align=center width="100%" cellpadding=0 cellspacing=2>
<tr>
<td><A HREF="os-procinfo.html"><img width=32 height=32 align=bottom border=0 alt="next"
 src="../icons/next.gif"></A></td>
<td><A HREF="allos.html"><img width=32 height=32 align=bottom border=0 alt="up"
 src="../icons/up.gif"></A></td>
<td><A HREF="allos.html"><img width=32 height=32 align=bottom border=0 alt="previous"
 src="../icons/previous.gif"></A></td>
<td align=center bgcolor="#99CCFF" width="100%">
 <b class=title>Python Library Reference</b></td>
<td><A HREF="contents.html"><img width=32 height=32 align=bottom border=0 alt="contents"
 src="../icons/contents.gif"></A></td>
<td><a
 href="modindex.html"><img width=32 height=32 align=bottom border=0 alt="modules"
 src="../icons/modules.gif"></a></td>
<td><A HREF="genindex.html"><img width=32 height=32 align=bottom border=0 alt="index"
 src="../icons/index.gif"></A></td>
</tr></table><b class=navlabel>Next:</b> <span class=sectref><A HREF="os-procinfo.html">6.1.1 Process Parameters</A></span>
<b class=navlabel>Up:</b> <span class=sectref><A HREF="allos.html">6. Generic Operating System</A></span>
<b class=navlabel>Previous:</b> <span class=sectref><A HREF="allos.html">6. Generic Operating System</A></span>
<br><hr></div>
<!--End of Navigation Panel-->

<H1><A NAME="SECTION008100000000000000000">
6.1 <tt class=module>os</tt> --
         Miscellaneous OS interfaces</A>
</H1>

<P>


<P>
This module provides a more portable way of using operating system
(OS) dependent functionality than importing an OS dependent built-in
module like <tt class=module>posix</tt> or <tt class=module>nt</tt>.

<P>
This module searches for an OS dependent built-in module like
<tt class=module>mac</tt> or <tt class=module>posix</tt> and exports the same functions and data
as found there.  The design of all Python's built-in OS dependent
modules is such that as long as the same functionality is available,
it uses the same interface; e.g., the function
<tt>os.stat(<var>path</var>)</tt> returns stat information about <var>path</var> in
the same format (which happens to have originated with the
POSIX interface).

<P>
Extensions peculiar to a particular OS are also available through the
<tt class=module>os</tt> module, but using them is of course a threat to
portability!

<P>
Note that after the first time <tt class=module>os</tt> is imported, there is
<i>no</i> performance penalty in using functions from <tt class=module>os</tt>
instead of directly from the OS dependent built-in module, so there
should be <i>no</i> reason not to use <tt class=module>os</tt>!

<P>
<dl><dt><b><a name="l2h-859"><tt class=exception>error</tt></a></b>
<dd>
This exception is raised when a function returns a
system-related error (e.g., not for illegal argument types).  This is
also known as the built-in exception <tt class=exception>OSError</tt>.  The
accompanying value is a pair containing the numeric error code from
<tt class=cdata>errno</tt> and the corresponding string, as would be printed by the
C function <tt class=cfunction>perror()</tt>.  See the module
<tt class=module><a href="module-errno.html">errno</a></tt><a name="l2h-862"></a>, which contains names for the
error codes defined by the underlying operating system.

<P>
When exceptions are classes, this exception carries two attributes,
<tt class=member>errno</tt> and <tt class=member>strerror</tt>.  The first holds the value of
the C <tt class=cdata>errno</tt> variable, and the latter holds the corresponding
error message from <tt class=cfunction>strerror()</tt>.  For exceptions that
involve a file system path (e.g. <tt class=function>chdir()</tt> or
<tt class=function>unlink()</tt>), the exception instance will contain a third
attribute, <tt class=member>filename</tt>, which is the file name passed to the
function.

<P>
When exceptions are strings, the string for the exception is
<tt>'OSError'</tt>.
</dl>

<P>
<dl><dt><b><a name="l2h-860"><tt>name</tt></a></b>
<dd>
The name of the OS dependent module imported.  The following names
have currently been registered: <tt>'posix'</tt>, <tt>'nt'</tt>,
<tt>'dos'</tt>, <tt>'mac'</tt>, <tt>'os2'</tt>.
</dl>

<P>
<dl><dt><b><a name="l2h-861"><tt>path</tt></a></b>
<dd>
The corresponding OS dependent standard module for pathname
operations, e.g., <tt class=module>posixpath</tt> or <tt class=module>macpath</tt>.  Thus, given
the proper imports, <tt>os.path.split(<var>file</var>)</tt> is equivalent to but
more portable than <tt>posixpath.split(<var>file</var>)</tt>.  Note that this 
is also a valid module: it may be imported directly as
<tt class=module><a href="module-os.path.html">os.path</a></tt>.
</dl>

<P>

<p><hr>
<!--Table of Child-Links-->


<UL>
<LI><A NAME="tex2html1838"
 HREF="os-procinfo.html">6.1.1 Process Parameters </A>
<LI><A NAME="tex2html1839"
 HREF="os-newstreams.html">6.1.2 File Object Creation </A>
<LI><A NAME="tex2html1840"
 HREF="os-fd-ops.html">6.1.3 File Descriptor Operations </A>
<LI><A NAME="tex2html1841"
 HREF="os-file-dir.html">6.1.4 Files and Directories </A>
<LI><A NAME="tex2html1842"
 HREF="os-process.html">6.1.5 Process Management </A>
<LI><A NAME="tex2html1843"
 HREF="os-path.html">6.1.6 Miscellanenous System Data </A>
</UL>
<!--End of Table of Child-Links-->
<p>
<div class=navigation><hr><table align=center width="100%" cellpadding=0 cellspacing=2>
<tr>
<td><A HREF="os-procinfo.html"><img width=32 height=32 align=bottom border=0 alt="next"
 src="../icons/next.gif"></A></td>
<td><A HREF="allos.html"><img width=32 height=32 align=bottom border=0 alt="up"
 src="../icons/up.gif"></A></td>
<td><A HREF="allos.html"><img width=32 height=32 align=bottom border=0 alt="previous"
 src="../icons/previous.gif"></A></td>
<td align=center bgcolor="#99CCFF" width="100%">
 <b class=title>Python Library Reference</b></td>
<td><A HREF="contents.html"><img width=32 height=32 align=bottom border=0 alt="contents"
 src="../icons/contents.gif"></A></td>
<td><a
 href="modindex.html"><img width=32 height=32 align=bottom border=0 alt="modules"
 src="../icons/modules.gif"></a></td>
<td><A HREF="genindex.html"><img width=32 height=32 align=bottom border=0 alt="index"
 src="../icons/index.gif"></A></td>
</tr></table><b class=navlabel>Next:</b> <span class=sectref><A HREF="os-procinfo.html">6.1.1 Process Parameters</A></span>
<b class=navlabel>Up:</b> <span class=sectref><A HREF="allos.html">6. Generic Operating System</A></span>
<b class=navlabel>Previous:</b> <span class=sectref><A HREF="allos.html">6. Generic Operating System</A></span>
</div>
<!--End of Navigation Panel-->
<ADDRESS>
<hr>Send comments on this document to <a href="mailto:python-docs@python.org">python-docs@python.org</a>.
</ADDRESS>
</BODY>
</HTML>
