* **`'IsADirectoryError'` and `'PermissionError'` can be risen by any.**
* **`'OSError'` is the parent class of all listed exceptions.**
### File
### File Object
```python
<file>.seek(0) # Moves to the start of the file.
<file>.seek(offset) # Moves 'offset' chars/bytes from the start.
@ -2151,7 +2151,7 @@ class MyMetaClass(type):
return type.__new__(cls, name, parents, attrs)
```
* **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.**
* **It receives the same arguments as init(), except for the first one that specifies the desired class of returned instance (MyMetaClass in our case).**
* **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).**
* **New() can also be called directly, usually from a new() method of a child class (**`def __new__(cls): return super().__new__(cls)`**), in which case init() is not called.**
<li><strong><codeclass="python hljs"><spanclass="hljs-string">'FileNotFoundError'</span></code> can be risen when reading with <codeclass="python hljs"><spanclass="hljs-string">'r'</span></code> or <codeclass="python hljs"><spanclass="hljs-string">'r+'</span></code>.</strong></li>
<li><strong><codeclass="python hljs"><spanclass="hljs-string">'FileExistsError'</span></code> can be risen when writing with <codeclass="python hljs"><spanclass="hljs-string">'x'</span></code>.</strong></li>
<li><strong><codeclass="python hljs"><spanclass="hljs-string">'IsADirectoryError'</span></code> and <codeclass="python hljs"><spanclass="hljs-string">'PermissionError'</span></code> can be risen by any.</strong></li>
<li><strong><codeclass="python hljs"><spanclass="hljs-string">'OSError'</span></code> is the parent class of all listed exceptions.</strong></li>
</ul></div><div><h3id="file">File</h3><pre><codeclass="python language-python hljs"><file>.seek(<spanclass="hljs-number">0</span>) <spanclass="hljs-comment"># Moves to the start of the file.</span>
</ul><div><h3id="fileobject">File Object</h3><pre><codeclass="python language-python hljs"><file>.seek(<spanclass="hljs-number">0</span>) <spanclass="hljs-comment"># Moves to the start of the file.</span>
<file>.seek(offset) <spanclass="hljs-comment"># Moves 'offset' chars/bytes from the start.</span>
<file>.seek(<spanclass="hljs-number">0</span>, <spanclass="hljs-number">2</span>) <spanclass="hljs-comment"># Moves to the end of the file.</span>
<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>
<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>
<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>
<li><strong>New() can also be called directly, usually from a new() method of a child class (</strong><codeclass="python hljs"><spanclass="hljs-function"><spanclass="hljs-keyword">def</span><spanclass="hljs-title">__new__</span><spanclass="hljs-params">(cls)</span>:</span><spanclass="hljs-keyword">return</span> super().__new__(cls)</code><strong>), in which case init() is not called.</strong></li>
</ul>
<div><h3id="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><codeclass="python language-python hljs"><spanclass="hljs-class"><spanclass="hljs-keyword">class</span><spanclass="hljs-title">MyClass</span><spanclass="hljs-params">(metaclass=MyMetaClass)</span>:</span>
xxxxxxxxxx