|
1409 | 1409 | <li><strong><code class="python hljs"><span class="hljs-string">'a+'</span></code> - Read and write from the end.</strong></li>
|
1410 | 1410 | <li><strong><code class="python hljs"><span class="hljs-string">'t'</span></code> - Text mode (default).</strong></li>
|
1411 | 1411 | <li><strong><code class="python hljs"><span class="hljs-string">'b'</span></code> - Binary mode.</strong></li>
|
1412 |
| -</ul></div><div><h3 id="exceptions-1">Exceptions</h3><ul> |
| 1412 | +</ul><div><h3 id="exceptions-1">Exceptions</h3><ul> |
1413 | 1413 | <li><strong><code class="python hljs"><span class="hljs-string">'FileNotFoundError'</span></code> can be risen when reading with <code class="python hljs"><span class="hljs-string">'r'</span></code> or <code class="python hljs"><span class="hljs-string">'r+'</span></code>.</strong></li>
|
1414 | 1414 | <li><strong><code class="python hljs"><span class="hljs-string">'FileExistsError'</span></code> can be risen when writing with <code class="python hljs"><span class="hljs-string">'x'</span></code>.</strong></li>
|
1415 | 1415 | <li><strong><code class="python hljs"><span class="hljs-string">'IsADirectoryError'</span></code> and <code class="python hljs"><span class="hljs-string">'PermissionError'</span></code> can be risen by any.</strong></li>
|
1416 | 1416 | <li><strong><code class="python hljs"><span class="hljs-string">'OSError'</span></code> is the parent class of all listed exceptions.</strong></li>
|
1417 |
| -</ul></div><div><h3 id="file">File</h3><pre><code class="python language-python hljs"><file>.seek(<span class="hljs-number">0</span>) <span class="hljs-comment"># Moves to the start of the file.</span> |
| 1417 | +</ul><div><h3 id="fileobject">File Object</h3><pre><code class="python language-python hljs"><file>.seek(<span class="hljs-number">0</span>) <span class="hljs-comment"># Moves to the start of the file.</span> |
1418 | 1418 | <file>.seek(offset) <span class="hljs-comment"># Moves 'offset' chars/bytes from the start.</span>
|
1419 | 1419 | <file>.seek(<span class="hljs-number">0</span>, <span class="hljs-number">2</span>) <span class="hljs-comment"># Moves to the end of the file.</span>
|
1420 | 1420 | <bin_file>.seek(±offset, <anchor>) <span class="hljs-comment"># Anchor: 0 start, 1 current pos., 2 end.</span>
|
1421 |
| -</code></pre></div> |
| 1421 | +</code></pre></div></div></div> |
1422 | 1422 |
|
1423 | 1423 |
|
1424 | 1424 |
|
|
1874 | 1874 |
|
1875 | 1875 | <ul>
|
1876 | 1876 | <li><strong>New() is a class method that gets called before init(). If it returns an instance of its class, then that instance gets passed to init() as a 'self' argument.</strong></li>
|
1877 |
| -<li><strong>It receives the same arguments as init(), except for the first one that specifies the desired class of returned instance (MyMetaClass in our case).</strong></li> |
| 1877 | +<li><strong>It receives the same arguments as init(), except for the first one that specifies the desired class of the returned instance (MyMetaClass in our case).</strong></li> |
1878 | 1878 | <li><strong>New() can also be called directly, usually from a new() method of a child class (</strong><code class="python hljs"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__new__</span><span class="hljs-params">(cls)</span>:</span> <span class="hljs-keyword">return</span> super().__new__(cls)</code><strong>), in which case init() is not called.</strong></li>
|
1879 | 1879 | </ul>
|
1880 | 1880 | <div><h3 id="metaclassattribute">Metaclass Attribute</h3><p><strong>Right before a class is created it checks if it has a 'metaclass' attribute defined. If not, it recursively checks if any of his parents has it defined and eventually comes to type().</strong></p><pre><code class="python language-python hljs"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyClass</span><span class="hljs-params">(metaclass=MyMetaClass)</span>:</span>
|
|
0 commit comments