⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 os-fd-ops.html

📁 一本很好的python的说明书,适合对python感兴趣的人
💻 HTML
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>6.1.3 File Descriptor Operations </title>
<META NAME="description" CONTENT="6.1.3 File Descriptor Operations ">
<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" tppabs="http://www.python.org/doc/current/lib/lib.css">
<LINK REL="next" href="os-file-dir.html" tppabs="http://www.python.org/doc/current/lib/os-file-dir.html">
<LINK REL="previous" href="os-newstreams.html" tppabs="http://www.python.org/doc/current/lib/os-newstreams.html">
<LINK REL="up" href="module-os.html" tppabs="http://www.python.org/doc/current/lib/module-os.html">
<LINK REL="next" href="os-file-dir.html" tppabs="http://www.python.org/doc/current/lib/os-file-dir.html">
</head>
<body>
<DIV CLASS="navigation"><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="os-newstreams.html" tppabs="http://www.python.org/doc/current/lib/os-newstreams.html"><img src="previous.gif" tppabs="http://www.python.org/doc/current/icons/previous.gif" border="0" height="32"
  alt="Previous Page" width="32"></A></td>
<td><A href="module-os.html" tppabs="http://www.python.org/doc/current/lib/module-os.html"><img src="up.gif" tppabs="http://www.python.org/doc/current/icons/up.gif" border="0" height="32"
  alt="Up One Level" width="32"></A></td>
<td><A href="os-file-dir.html" tppabs="http://www.python.org/doc/current/lib/os-file-dir.html"><img src="next.gif" tppabs="http://www.python.org/doc/current/icons/next.gif" border="0" height="32"
  alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td><A href="contents.html" tppabs="http://www.python.org/doc/current/lib/contents.html"><img src="contents.gif" tppabs="http://www.python.org/doc/current/icons/contents.gif" border="0" height="32"
  alt="Contents" width="32"></A></td>
<td><a href="modindex.html" tppabs="http://www.python.org/doc/current/lib/modindex.html" title="Module Index"><img src="modules.gif" tppabs="http://www.python.org/doc/current/icons/modules.gif" border="0" height="32"
  alt="Module Index" width="32"></a></td>
<td><A href="genindex.html" tppabs="http://www.python.org/doc/current/lib/genindex.html"><img src="index.gif" tppabs="http://www.python.org/doc/current/icons/index.gif" border="0" height="32"
  alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="os-newstreams.html" tppabs="http://www.python.org/doc/current/lib/os-newstreams.html">6.1.2 File Object Creation</A>
<b class="navlabel">Up:</b> <a class="sectref" href="module-os.html" tppabs="http://www.python.org/doc/current/lib/module-os.html">6.1 os  </A>
<b class="navlabel">Next:</b> <a class="sectref" href="os-file-dir.html" tppabs="http://www.python.org/doc/current/lib/os-file-dir.html">6.1.4 Files and Directories</A>
<br><hr></DIV>
<!--End of Navigation Panel-->

<H2>
<BR>
6.1.3 File Descriptor Operations 
</H2>

<P>
These functions operate on I/O streams referred to
using file descriptors.

<P>
<dl><dt><b><a name='l2h-913'><tt class='function'>close</tt></a></b> (<var>fd</var>)
<dd>
Close file descriptor <var>fd</var>.
Availability: Macintosh, Unix, Windows.

<P>
Note: this function is intended for low-level I/O and must be applied
to a file descriptor as returned by <tt class="function">open()</tt> or
<tt class="function">pipe()</tt>.  To close a ``file object'' returned by the
built-in function <tt class="function">open()</tt> or by <tt class="function">popen()</tt> or
<tt class="function">fdopen()</tt>, use its <tt class="method">close()</tt> method.
</dl>

<P>
<dl><dt><b><a name='l2h-914'><tt class='function'>dup</tt></a></b> (<var>fd</var>)
<dd>
Return a duplicate of file descriptor <var>fd</var>.
Availability: Macintosh, Unix, Windows.
</dl>

<P>
<dl><dt><b><a name='l2h-915'><tt class='function'>dup2</tt></a></b> (<var>fd, fd2</var>)
<dd>
Duplicate file descriptor <var>fd</var> to <var>fd2</var>, closing the latter
first if necessary.
Availability: Unix, Windows.
</dl>

<P>
<dl><dt><b><a name='l2h-916'><tt class='function'>fpathconf</tt></a></b> (<var>fd, name</var>)
<dd>
Return system configuration information relevant to an open file.
<var>name</var> 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, Unix95, Unix98, and
others).  Some platforms define additional names as well.  The names
known to the host operating system are given in the
<code>pathconf_names</code> dictionary.  For configuration variables not
included in that mapping, passing an integer for <var>name</var> is also
accepted.
Availability: Unix.

<P>
If <var>name</var> is a string and is not known, <tt class="exception">ValueError</tt> is
raised.  If a specific value for <var>name</var> is not supported by the
host system, even if it is included in <code>pathconf_names</code>, an
<tt class="exception">OSError</tt> is raised with <tt class="constant">errno.EINVAL</tt> for the
error number.
</dl>

<P>
<dl><dt><b><a name='l2h-917'><tt class='function'>fstat</tt></a></b> (<var>fd</var>)
<dd>
Return status for file descriptor <var>fd</var>, like <tt class="function">stat()</tt>.
Availability: Unix, Windows.
</dl>

<P>
<dl><dt><b><a name='l2h-918'><tt class='function'>fstatvfs</tt></a></b> (<var>fd</var>)
<dd>
Return information about the filesystem containing the file associated
with file descriptor <var>fd</var>, like <tt class="function">statvfs()</tt>.
Availability: Unix.
</dl>

<P>
<dl><dt><b><a name='l2h-919'><tt class='function'>ftruncate</tt></a></b> (<var>fd, length</var>)
<dd>
Truncate the file corresponding to file descriptor <var>fd</var>, 
so that it is at most <var>length</var> bytes in size.
Availability: Unix.
</dl>

<P>
<dl><dt><b><a name='l2h-920'><tt class='function'>isatty</tt></a></b> (<var>fd</var>)
<dd>
Return <code>1</code> if the file descriptor <var>fd</var> is open and connected to a
tty(-like) device, else <code>0</code>.
Availability: Unix
</dl>

<P>
<dl><dt><b><a name='l2h-921'><tt class='function'>lseek</tt></a></b> (<var>fd, pos, how</var>)
<dd>
Set the current position of file descriptor <var>fd</var> to position
<var>pos</var>, modified by <var>how</var>: <code>0</code> to set the position
relative to the beginning of the file; <code>1</code> to set it relative to
the current position; <code>2</code> to set it relative to the end of the
file.
Availability: Macintosh, Unix, Windows.
</dl>

<P>
<dl><dt><b><a name='l2h-922'><tt class='function'>open</tt></a></b> (<var>file, flags</var><big>[</big><var>, mode</var><big>]</big>)
<dd>
Open the file <var>file</var> and set various flags according to
<var>flags</var> and possibly its mode according to <var>mode</var>.
The default <var>mode</var> is <code>0777</code> (octal), and the current umask
value is first masked out.  Return the file descriptor for the newly
opened file.
Availability: Macintosh, Unix, Windows.

<P>
For a description of the flag and mode values, see the C run-time
documentation; flag constants (like <tt class="constant">O_RDONLY</tt> and
<tt class="constant">O_WRONLY</tt>) are defined in this module too (see below).

<P>
Note: this function is intended for low-level I/O.  For normal usage,
use the built-in function <tt class="function">open()</tt>, which returns a ``file
object'' with <tt class="method">read()</tt> and <tt class="method">write()</tt> methods (and many
more).
</dl>

<P>
<dl><dt><b><a name='l2h-923'><tt class='function'>openpty</tt></a></b> ()
<dd>
Open a new pseudo-terminal pair. Return a pair of file descriptors
<code>(<var>master</var>, <var>slave</var>)</code> for the pty and the tty,
respectively. For a (slightly) more portable approach, use the
<tt class='module'><a href="module-pty.html" tppabs="http://www.python.org/doc/current/lib/module-pty.html">pty</a></tt> module.
Availability: Some flavors of Unix
</dl>

<P>
<dl><dt><b><a name='l2h-924'><tt class='function'>pipe</tt></a></b> ()
<dd>
Create a pipe.  Return a pair of file descriptors <code>(<var>r</var>,
<var>w</var>)</code> usable for reading and writing, respectively.
Availability: Unix, Windows.
</dl>

<P>
<dl><dt><b><a name='l2h-925'><tt class='function'>read</tt></a></b> (<var>fd, n</var>)
<dd>
Read at most <var>n</var> bytes from file descriptor <var>fd</var>.
Return a string containing the bytes read.
Availability: Macintosh, Unix, Windows.

<P>
Note: this function is intended for low-level I/O and must be applied
to a file descriptor as returned by <tt class="function">open()</tt> or
<tt class="function">pipe()</tt>.  To read a ``file object'' returned by the
built-in function <tt class="function">open()</tt> or by <tt class="function">popen()</tt> or
<tt class="function">fdopen()</tt>, or <code>sys.stdin</code>, use its
<tt class="method">read()</tt> or <tt class="method">readline()</tt> methods.
</dl>

<P>
<dl><dt><b><a name='l2h-926'><tt class='function'>tcgetpgrp</tt></a></b> (<var>fd</var>)
<dd>
Return the process group associated with the terminal given by
<var>fd</var> (an open file descriptor as returned by <tt class="function">open()</tt>).
Availability: Unix.
</dl>

<P>
<dl><dt><b><a name='l2h-927'><tt class='function'>tcsetpgrp</tt></a></b> (<var>fd, pg</var>)
<dd>
Set the process group associated with the terminal given by
<var>fd</var> (an open file descriptor as returned by <tt class="function">open()</tt>)
to <var>pg</var>.
Availability: Unix.
</dl>

<P>
<dl><dt><b><a name='l2h-928'><tt class='function'>ttyname</tt></a></b> (<var>fd</var>)
<dd>
Return a string which specifies the terminal device associated with
file-descriptor <var>fd</var>.  If <var>fd</var> is not associated with a terminal
device, an exception is raised.
Availability: Unix.
</dl>

<P>
<dl><dt><b><a name='l2h-929'><tt class='function'>write</tt></a></b> (<var>fd, str</var>)
<dd>
Write the string <var>str</var> to file descriptor <var>fd</var>.
Return the number of bytes actually written.
Availability: Macintosh, Unix, Windows.

<P>
Note: this function is intended for low-level I/O and must be applied
to a file descriptor as returned by <tt class="function">open()</tt> or
<tt class="function">pipe()</tt>.  To write a ``file object'' returned by the
built-in function <tt class="function">open()</tt> or by <tt class="function">popen()</tt> or
<tt class="function">fdopen()</tt>, or <code>sys.stdout</code> or <code>sys.stderr</code>, use
its <tt class="method">write()</tt> method.
</dl>

<P>
The following data items are available for use in constructing the
<var>flags</var> parameter to the <tt class="function">open()</tt> function.

<P>
<dl><dt><b><a name='l2h-930'><tt>O_RDONLY</tt></a></b>
<dd>
<dt><b><a name='l2h-933'><tt>O_WRONLY</tt></a></b><dd>
<dt><b><a name='l2h-934'><tt>O_RDWR</tt></a></b><dd>
<dt><b><a name='l2h-935'><tt>O_NDELAY</tt></a></b><dd>
<dt><b><a name='l2h-936'><tt>O_NONBLOCK</tt></a></b><dd>
<dt><b><a name='l2h-937'><tt>O_APPEND</tt></a></b><dd>
<dt><b><a name='l2h-938'><tt>O_DSYNC</tt></a></b><dd>
<dt><b><a name='l2h-939'><tt>O_RSYNC</tt></a></b><dd>
<dt><b><a name='l2h-940'><tt>O_SYNC</tt></a></b><dd>
<dt><b><a name='l2h-941'><tt>O_NOCTTY</tt></a></b><dd>
<dt><b><a name='l2h-942'><tt>O_CREAT</tt></a></b><dd>
<dt><b><a name='l2h-943'><tt>O_EXCL</tt></a></b><dd>
<dt><b><a name='l2h-944'><tt>O_TRUNC</tt></a></b><dd>
Options for the <var>flag</var> argument to the <tt class="function">open()</tt> function.
These can be bit-wise OR'd together.
Availability: Macintosh, Unix, Windows.
</dl>

<P>
<dl><dt><b><a name='l2h-931'><tt>O_BINARY</tt></a></b>
<dd>
Option for the <var>flag</var> argument to the <tt class="function">open()</tt> function.
This can be bit-wise OR'd together with those listed above.
Availability: Macintosh, Windows.
</dl>

<P>

<DIV CLASS="navigation"><p><hr><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="os-newstreams.html" tppabs="http://www.python.org/doc/current/lib/os-newstreams.html"><img src="previous.gif" tppabs="http://www.python.org/doc/current/icons/previous.gif" border="0" height="32"
  alt="Previous Page" width="32"></A></td>
<td><A href="module-os.html" tppabs="http://www.python.org/doc/current/lib/module-os.html"><img src="up.gif" tppabs="http://www.python.org/doc/current/icons/up.gif" border="0" height="32"
  alt="Up One Level" width="32"></A></td>
<td><A href="os-file-dir.html" tppabs="http://www.python.org/doc/current/lib/os-file-dir.html"><img src="next.gif" tppabs="http://www.python.org/doc/current/icons/next.gif" border="0" height="32"
  alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td><A href="contents.html" tppabs="http://www.python.org/doc/current/lib/contents.html"><img src="contents.gif" tppabs="http://www.python.org/doc/current/icons/contents.gif" border="0" height="32"
  alt="Contents" width="32"></A></td>
<td><a href="modindex.html" tppabs="http://www.python.org/doc/current/lib/modindex.html" title="Module Index"><img src="modules.gif" tppabs="http://www.python.org/doc/current/icons/modules.gif" border="0" height="32"
  alt="Module Index" width="32"></a></td>
<td><A href="genindex.html" tppabs="http://www.python.org/doc/current/lib/genindex.html"><img src="index.gif" tppabs="http://www.python.org/doc/current/icons/index.gif" border="0" height="32"
  alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="os-newstreams.html" tppabs="http://www.python.org/doc/current/lib/os-newstreams.html">6.1.2 File Object Creation</A>
<b class="navlabel">Up:</b> <a class="sectref" href="module-os.html" tppabs="http://www.python.org/doc/current/lib/module-os.html">6.1 os  </A>
<b class="navlabel">Next:</b> <a class="sectref" href="os-file-dir.html" tppabs="http://www.python.org/doc/current/lib/os-file-dir.html">6.1.4 Files and Directories</A>
</DIV>
<!--End of Navigation Panel-->
<ADDRESS>
<hr>See <i><a href="about.html" tppabs="http://www.python.org/doc/current/lib/about.html">About this document...</a></i> for information on suggesting changes.
</ADDRESS>
</BODY>
</HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -