home *** CD-ROM | disk | FTP | other *** search
- <TITLE>os -- Python library reference</TITLE>
- Next: <A HREF="../t/time" TYPE="Next">time</A>
- Prev: <A HREF="../g/generic_operating_system_services" TYPE="Prev">Generic Operating System Services</A>
- Up: <A HREF="../g/generic_operating_system_services" TYPE="Up">Generic Operating System Services</A>
- Top: <A HREF="../t/top" TYPE="Top">Top</A>
- <H1>6.1. Standard Module <CODE>os</CODE></H1>
- This module provides a more portable way of using operating system
- (OS) dependent functionality than importing an OS dependent built-in
- module like <CODE>posix</CODE>.
- <P>
- When the optional built-in module <CODE>posix</CODE> is available, this
- module exports the same functions and data as <CODE>posix</CODE>; otherwise,
- it searches for an OS dependent built-in module like <CODE>mac</CODE> 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 <CODE>os.stat(<VAR>file</VAR>)</CODE> returns stat info about a <VAR>file</VAR> in a
- format compatible with the POSIX interface.
- <P>
- Extensions peculiar to a particular OS are also available through the
- <CODE>os</CODE> module, but using them is of course a threat to portability!
- <P>
- Note that after the first time <CODE>os</CODE> is imported, there is <I>no</I>
- performance penalty in using functions from <CODE>os</CODE> instead of
- directly from the OS dependent built-in module, so there should be
- <I>no</I> reason not to use <CODE>os</CODE>!
- <P>
- In addition to whatever the correct OS dependent module exports, the
- following variables and functions are always exported by <CODE>os</CODE>:
- <P>
- <DL><DT><B>name</B> -- data of module os<DD>
- The name of the OS dependent module imported. The following names
- have currently been registered: <CODE>'posix'</CODE>, <CODE>'nt'</CODE>,
- <CODE>'dos'</CODE>, <CODE>'mac'</CODE>.
- </DL>
- <DL><DT><B>path</B> -- data of module os<DD>
- The corresponding OS dependent standard module for pathname
- operations, e.g., <CODE>posixpath</CODE> or <CODE>macpath</CODE>. Thus, (given
- the proper imports), <CODE>os.path.split(<VAR>file</VAR>)</CODE> is equivalent to but
- more portable than <CODE>posixpath.split(<VAR>file</VAR>)</CODE>.
- </DL>
- <DL><DT><B>curdir</B> -- data of module os<DD>
- The constant string used by the OS to refer to the current directory,
- e.g. <CODE>'.'</CODE> for POSIX or <CODE>':'</CODE> for the Mac.
- </DL>
- <DL><DT><B>pardir</B> -- data of module os<DD>
- The constant string used by the OS to refer to the parent directory,
- e.g. <CODE>'..'</CODE> for POSIX or <CODE>'::'</CODE> for the Mac.
- </DL>
- <DL><DT><B>sep</B> -- data of module os<DD>
- The character used by the OS to separate pathname components, e.g.
- <CODE>'/'</CODE> for POSIX or <CODE>':'</CODE> for the Mac. Note that knowing this
- is not sufficient to be able to parse or concatenate pathnames---better
- use <CODE>os.path.split()</CODE> and <CODE>os.path.join()</CODE>---but it is
- occasionally useful.
- </DL>
- <DL><DT><B>pathsep</B> -- data of module os<DD>
- The character conventionally used by the OS to separate search patch
- components (as in <CODE>$PATH</CODE>), e.g. <CODE>':'</CODE> for POSIX or
- <CODE>';'</CODE> for MS-DOS.
- </DL>
- <DL><DT><B>defpath</B> -- data of module os<DD>
- The default search path used by <CODE>os.exec*p*()</CODE> if the environment
- doesn't have a <CODE>'PATH'</CODE> key.
- </DL>
- <DL><DT><B>execl</B> (<VAR>path</VAR>, <VAR>arg0</VAR>, <VAR>arg1</VAR>, ...) -- function of module os<DD>
- This is equivalent to
- <CODE>os.execv(<VAR>path</VAR>, (<VAR>arg0</VAR>, <VAR>arg1</VAR>, ...))</CODE>.
- </DL>
- <DL><DT><B>execle</B> (<VAR>path</VAR>, <VAR>arg0</VAR>, <VAR>arg1</VAR>, ..., <VAR>env</VAR>) -- function of module os<DD>
- This is equivalent to
- <CODE>os.execve(<VAR>path</VAR>, (<VAR>arg0</VAR>, <VAR>arg1</VAR>, ...), <VAR>env</VAR>)</CODE>.
- </DL>
- <DL><DT><B>execlp</B> (<VAR>path</VAR>, <VAR>arg0</VAR>, <VAR>arg1</VAR>, ...) -- function of module os<DD>
- This is equivalent to
- <CODE>os.execvp(<VAR>path</VAR>, (<VAR>arg0</VAR>, <VAR>arg1</VAR>, ...))</CODE>.
- </DL>
- <DL><DT><B>execvp</B> (<VAR>path</VAR>, <VAR>args</VAR>) -- function of module os<DD>
- This is like <CODE>os.execv(<VAR>path</VAR>, <VAR>args</VAR>)</CODE> but duplicates
- the shell's actions in searching for an executable file in a list of
- directories. The directory list is obtained from
- <CODE>os.environ['PATH']</CODE>.
- </DL>
- <DL><DT><B>execvpe</B> (<VAR>path</VAR>, <VAR>args</VAR>, <VAR>env</VAR>) -- function of module os<DD>
- This is a cross between <CODE>os.execve()</CODE> and <CODE>os.execvp()</CODE>.
- The directory list is obtained from <CODE><VAR>env</VAR>['PATH']</CODE>.
- </DL>
- (The functions <CODE>os.execv()</CODE> and <CODE>execve()</CODE> are not
- documented here, since they are implemented by the OS dependent
- module. If the OS dependent module doesn't define either of these,
- the functions that rely on it will raise an exception. They are
- documented in the section on module <CODE>posix</CODE>, together with all
- other functions that <CODE>os</CODE> imports from the OS dependent module.)
-