~dkuhlman/python-training-materials/Materials

« back to all changes in this revision

Viewing changes to python-3.5.2-docs-html/c-api/file.html

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

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 
2
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
3
 
 
4
 
 
5
<html xmlns="http://www.w3.org/1999/xhtml">
 
6
  <head>
 
7
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 
8
    
 
9
    <title>File Objects &mdash; Python 3.5.2 documentation</title>
 
10
    
 
11
    <link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
 
12
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
 
13
    
 
14
    <script type="text/javascript">
 
15
      var DOCUMENTATION_OPTIONS = {
 
16
        URL_ROOT:    '../',
 
17
        VERSION:     '3.5.2',
 
18
        COLLAPSE_INDEX: false,
 
19
        FILE_SUFFIX: '.html',
 
20
        HAS_SOURCE:  true
 
21
      };
 
22
    </script>
 
23
    <script type="text/javascript" src="../_static/jquery.js"></script>
 
24
    <script type="text/javascript" src="../_static/underscore.js"></script>
 
25
    <script type="text/javascript" src="../_static/doctools.js"></script>
 
26
    <script type="text/javascript" src="../_static/sidebar.js"></script>
 
27
    <link rel="search" type="application/opensearchdescription+xml"
 
28
          title="Search within Python 3.5.2 documentation"
 
29
          href="../_static/opensearch.xml"/>
 
30
    <link rel="author" title="About these documents" href="../about.html" />
 
31
    <link rel="copyright" title="Copyright" href="../copyright.html" />
 
32
    <link rel="top" title="Python 3.5.2 documentation" href="../contents.html" />
 
33
    <link rel="up" title="Concrete Objects Layer" href="concrete.html" />
 
34
    <link rel="next" title="Module Objects" href="module.html" />
 
35
    <link rel="prev" title="Code Objects" href="code.html" />
 
36
    <link rel="shortcut icon" type="image/png" href="../_static/py.png" />
 
37
    
 
38
    <script type="text/javascript" src="../_static/copybutton.js"></script>
 
39
    <script type="text/javascript" src="../_static/version_switch.js"></script>
 
40
    
 
41
    
 
42
 
 
43
 
 
44
  </head>
 
45
  <body role="document">  
 
46
    <div class="related" role="navigation" aria-label="related navigation">
 
47
      <h3>Navigation</h3>
 
48
      <ul>
 
49
        <li class="right" style="margin-right: 10px">
 
50
          <a href="../genindex.html" title="General Index"
 
51
             accesskey="I">index</a></li>
 
52
        <li class="right" >
 
53
          <a href="../py-modindex.html" title="Python Module Index"
 
54
             >modules</a> |</li>
 
55
        <li class="right" >
 
56
          <a href="module.html" title="Module Objects"
 
57
             accesskey="N">next</a> |</li>
 
58
        <li class="right" >
 
59
          <a href="code.html" title="Code Objects"
 
60
             accesskey="P">previous</a> |</li>
 
61
        <li><img src="../_static/py.png" alt=""
 
62
                 style="vertical-align: middle; margin-top: -1px"/></li>
 
63
        <li><a href="https://www.python.org/">Python</a> &raquo;</li>
 
64
        <li>
 
65
          <span class="version_switcher_placeholder">3.5.2</span>
 
66
          <a href="../index.html">Documentation </a> &raquo;
 
67
        </li>
 
68
 
 
69
          <li class="nav-item nav-item-1"><a href="index.html" >Python/C API Reference Manual</a> &raquo;</li>
 
70
          <li class="nav-item nav-item-2"><a href="concrete.html" accesskey="U">Concrete Objects Layer</a> &raquo;</li>
 
71
    <li class="right">
 
72
        
 
73
 
 
74
    <div class="inline-search" style="display: none" role="search">
 
75
        <form class="inline-search" action="../search.html" method="get">
 
76
          <input placeholder="Quick search" type="text" name="q" />
 
77
          <input type="submit" value="Go" />
 
78
          <input type="hidden" name="check_keywords" value="yes" />
 
79
          <input type="hidden" name="area" value="default" />
 
80
        </form>
 
81
    </div>
 
82
    <script type="text/javascript">$('.inline-search').show(0);</script>
 
83
         |
 
84
    </li>
 
85
 
 
86
      </ul>
 
87
    </div>    
 
88
 
 
89
    <div class="document">
 
90
      <div class="documentwrapper">
 
91
        <div class="bodywrapper">
 
92
          <div class="body" role="main">
 
93
            
 
94
  <div class="section" id="file-objects">
 
95
<span id="fileobjects"></span><h1>File Objects<a class="headerlink" href="#file-objects" title="Permalink to this headline">¶</a></h1>
 
96
<p id="index-0">These APIs are a minimal emulation of the Python 2 C API for built-in file
 
97
objects, which used to rely on the buffered I/O (<code class="xref c c-type docutils literal"><span class="pre">FILE*</span></code>) support
 
98
from the C standard library.  In Python 3, files and streams use the new
 
99
<a class="reference internal" href="../library/io.html#module-io" title="io: Core tools for working with streams."><code class="xref py py-mod docutils literal"><span class="pre">io</span></code></a> module, which defines several layers over the low-level unbuffered
 
100
I/O of the operating system.  The functions described below are
 
101
convenience C wrappers over these new APIs, and meant mostly for internal
 
102
error reporting in the interpreter; third-party code is advised to access
 
103
the <a class="reference internal" href="../library/io.html#module-io" title="io: Core tools for working with streams."><code class="xref py py-mod docutils literal"><span class="pre">io</span></code></a> APIs instead.</p>
 
104
<dl class="function">
 
105
<dt id="c.PyFile_FromFd">
 
106
<code class="descname">PyFile_FromFd</code><span class="sig-paren">(</span>int<em>&nbsp;fd</em>, const char<em>&nbsp;*name</em>, const char<em>&nbsp;*mode</em>, int<em>&nbsp;buffering</em>, const char<em>&nbsp;*encoding</em>, const char<em>&nbsp;*errors</em>, const char<em>&nbsp;*newline</em>, int<em>&nbsp;closefd</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyFile_FromFd" title="Permalink to this definition">¶</a></dt>
 
107
<dd><p>Create a Python file object from the file descriptor of an already
 
108
opened file <em>fd</em>.  The arguments <em>name</em>, <em>encoding</em>, <em>errors</em> and <em>newline</em>
 
109
can be <em>NULL</em> to use the defaults; <em>buffering</em> can be <em>-1</em> to use the
 
110
default. <em>name</em> is ignored and kept for backward compatibility. Return
 
111
<em>NULL</em> on failure. For a more comprehensive description of the arguments,
 
112
please refer to the <a class="reference internal" href="../library/io.html#io.open" title="io.open"><code class="xref py py-func docutils literal"><span class="pre">io.open()</span></code></a> function documentation.</p>
 
113
<div class="admonition warning">
 
114
<p class="first admonition-title">Warning</p>
 
115
<p class="last">Since Python streams have their own buffering layer, mixing them with
 
116
OS-level file descriptors can produce various issues (such as unexpected
 
117
ordering of data).</p>
 
118
</div>
 
119
<div class="versionchanged">
 
120
<p><span class="versionmodified">Changed in version 3.2: </span>Ignore <em>name</em> attribute.</p>
 
121
</div>
 
122
</dd></dl>
 
123
 
 
124
<dl class="function">
 
125
<dt id="c.PyObject_AsFileDescriptor">
 
126
int <code class="descname">PyObject_AsFileDescriptor</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*p</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyObject_AsFileDescriptor" title="Permalink to this definition">¶</a></dt>
 
127
<dd><p>Return the file descriptor associated with <em>p</em> as an <code class="xref c c-type docutils literal"><span class="pre">int</span></code>.  If the
 
128
object is an integer, its value is returned.  If not, the
 
129
object&#8217;s <a class="reference internal" href="../library/io.html#io.IOBase.fileno" title="io.IOBase.fileno"><code class="xref py py-meth docutils literal"><span class="pre">fileno()</span></code></a> method is called if it exists; the
 
130
method must return an integer, which is returned as the file descriptor
 
131
value.  Sets an exception and returns <code class="docutils literal"><span class="pre">-1</span></code> on failure.</p>
 
132
</dd></dl>
 
133
 
 
134
<dl class="function">
 
135
<dt id="c.PyFile_GetLine">
 
136
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyFile_GetLine</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*p</em>, int<em>&nbsp;n</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyFile_GetLine" title="Permalink to this definition">¶</a></dt>
 
137
<dd><em class="refcount">Return value: New reference.</em><p id="index-1">Equivalent to <code class="docutils literal"><span class="pre">p.readline([n])</span></code>, this function reads one line from the
 
138
object <em>p</em>.  <em>p</em> may be a file object or any object with a
 
139
<a class="reference internal" href="../library/io.html#io.IOBase.readline" title="io.IOBase.readline"><code class="xref py py-meth docutils literal"><span class="pre">readline()</span></code></a>
 
140
method.  If <em>n</em> is <code class="docutils literal"><span class="pre">0</span></code>, exactly one line is read, regardless of the length of
 
141
the line.  If <em>n</em> is greater than <code class="docutils literal"><span class="pre">0</span></code>, no more than <em>n</em> bytes will be read
 
142
from the file; a partial line can be returned.  In both cases, an empty string
 
143
is returned if the end of the file is reached immediately.  If <em>n</em> is less than
 
144
<code class="docutils literal"><span class="pre">0</span></code>, however, one line is read regardless of length, but <a class="reference internal" href="../library/exceptions.html#EOFError" title="EOFError"><code class="xref py py-exc docutils literal"><span class="pre">EOFError</span></code></a> is
 
145
raised if the end of the file is reached immediately.</p>
 
146
</dd></dl>
 
147
 
 
148
<dl class="function">
 
149
<dt id="c.PyFile_WriteObject">
 
150
int <code class="descname">PyFile_WriteObject</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*obj</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*p</em>, int<em>&nbsp;flags</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyFile_WriteObject" title="Permalink to this definition">¶</a></dt>
 
151
<dd><p id="index-2">Write object <em>obj</em> to file object <em>p</em>.  The only supported flag for <em>flags</em> is
 
152
<code class="xref py py-const docutils literal"><span class="pre">Py_PRINT_RAW</span></code>; if given, the <a class="reference internal" href="../library/stdtypes.html#str" title="str"><code class="xref py py-func docutils literal"><span class="pre">str()</span></code></a> of the object is written
 
153
instead of the <a class="reference internal" href="../library/functions.html#repr" title="repr"><code class="xref py py-func docutils literal"><span class="pre">repr()</span></code></a>.  Return <code class="docutils literal"><span class="pre">0</span></code> on success or <code class="docutils literal"><span class="pre">-1</span></code> on failure; the
 
154
appropriate exception will be set.</p>
 
155
</dd></dl>
 
156
 
 
157
<dl class="function">
 
158
<dt id="c.PyFile_WriteString">
 
159
int <code class="descname">PyFile_WriteString</code><span class="sig-paren">(</span>const char<em>&nbsp;*s</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em>&nbsp;*p</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyFile_WriteString" title="Permalink to this definition">¶</a></dt>
 
160
<dd><p>Write string <em>s</em> to file object <em>p</em>.  Return <code class="docutils literal"><span class="pre">0</span></code> on success or <code class="docutils literal"><span class="pre">-1</span></code> on
 
161
failure; the appropriate exception will be set.</p>
 
162
</dd></dl>
 
163
 
 
164
</div>
 
165
 
 
166
 
 
167
          </div>
 
168
        </div>
 
169
      </div>
 
170
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
 
171
        <div class="sphinxsidebarwrapper">
 
172
  <h4>Previous topic</h4>
 
173
  <p class="topless"><a href="code.html"
 
174
                        title="previous chapter">Code Objects</a></p>
 
175
  <h4>Next topic</h4>
 
176
  <p class="topless"><a href="module.html"
 
177
                        title="next chapter">Module Objects</a></p>
 
178
  <div role="note" aria-label="source link">
 
179
    <h3>This Page</h3>
 
180
    <ul class="this-page-menu">
 
181
      <li><a href="../bugs.html">Report a Bug</a></li>
 
182
      <li><a href="../_sources/c-api/file.txt"
 
183
            rel="nofollow">Show Source</a></li>
 
184
    </ul>
 
185
  </div>
 
186
        </div>
 
187
      </div>
 
188
      <div class="clearer"></div>
 
189
    </div>  
 
190
    <div class="related" role="navigation" aria-label="related navigation">
 
191
      <h3>Navigation</h3>
 
192
      <ul>
 
193
        <li class="right" style="margin-right: 10px">
 
194
          <a href="../genindex.html" title="General Index"
 
195
             >index</a></li>
 
196
        <li class="right" >
 
197
          <a href="../py-modindex.html" title="Python Module Index"
 
198
             >modules</a> |</li>
 
199
        <li class="right" >
 
200
          <a href="module.html" title="Module Objects"
 
201
             >next</a> |</li>
 
202
        <li class="right" >
 
203
          <a href="code.html" title="Code Objects"
 
204
             >previous</a> |</li>
 
205
        <li><img src="../_static/py.png" alt=""
 
206
                 style="vertical-align: middle; margin-top: -1px"/></li>
 
207
        <li><a href="https://www.python.org/">Python</a> &raquo;</li>
 
208
        <li>
 
209
          <span class="version_switcher_placeholder">3.5.2</span>
 
210
          <a href="../index.html">Documentation </a> &raquo;
 
211
        </li>
 
212
 
 
213
          <li class="nav-item nav-item-1"><a href="index.html" >Python/C API Reference Manual</a> &raquo;</li>
 
214
          <li class="nav-item nav-item-2"><a href="concrete.html" >Concrete Objects Layer</a> &raquo;</li>
 
215
    <li class="right">
 
216
        
 
217
 
 
218
    <div class="inline-search" style="display: none" role="search">
 
219
        <form class="inline-search" action="../search.html" method="get">
 
220
          <input placeholder="Quick search" type="text" name="q" />
 
221
          <input type="submit" value="Go" />
 
222
          <input type="hidden" name="check_keywords" value="yes" />
 
223
          <input type="hidden" name="area" value="default" />
 
224
        </form>
 
225
    </div>
 
226
    <script type="text/javascript">$('.inline-search').show(0);</script>
 
227
         |
 
228
    </li>
 
229
 
 
230
      </ul>
 
231
    </div>  
 
232
    <div class="footer">
 
233
    &copy; <a href="../copyright.html">Copyright</a> 2001-2016, Python Software Foundation.
 
234
    <br />
 
235
    The Python Software Foundation is a non-profit corporation.
 
236
    <a href="https://www.python.org/psf/donations/">Please donate.</a>
 
237
    <br />
 
238
    Last updated on Sep 23, 2016.
 
239
    <a href="../bugs.html">Found a bug</a>?
 
240
    <br />
 
241
    Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.3.3.
 
242
    </div>
 
243
 
 
244
  </body>
 
245
</html>
 
 
b'\\ No newline at end of file'