|
@ -976,7 +976,7 @@ Z = dataclasses.make_dataclass(<span class="hljs-string">'Z'</span>, [<span clas |
|
|
</ul> |
|
|
</ul> |
|
|
<h3 id="slots">Slots</h3> |
|
|
<h3 id="slots">Slots</h3> |
|
|
<p><strong>Mechanism that restricts objects to attributes listed in 'slots' and significantly reduces their memory footprint.</strong></p> |
|
|
<p><strong>Mechanism that restricts objects to attributes listed in 'slots' and significantly reduces their memory footprint.</strong></p> |
|
|
<pre><code class="python hljs"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyClassWithSlots</span>:</span> |
|
|
|
|
|
|
|
|
<pre><code class="python language-python hljs"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyClassWithSlots</span>:</span> |
|
|
__slots__ = [<span class="hljs-string">'a'</span>] |
|
|
__slots__ = [<span class="hljs-string">'a'</span>] |
|
|
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span><span class="hljs-params">(self)</span>:</span> |
|
|
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span><span class="hljs-params">(self)</span>:</span> |
|
|
self.a = <span class="hljs-number">1</span> |
|
|
self.a = <span class="hljs-number">1</span> |
|
|