mirror of
https://github.com/kennethreitz/dive-into-python3.git
synced 2026-06-05 15:00:18 +00:00
clarified exactly what gets initialized in __init__
This commit is contained in:
+1
-1
@@ -258,7 +258,7 @@ rules = LazyRules()</code></pre>
|
||||
<a> self.cache = [] <span class=u>②</span></a></code></pre>
|
||||
<ol>
|
||||
<li>When we instantiate the <code>LazyRules</code> class, open the pattern file but don’t read anything from it. (That comes later.)
|
||||
<li>After opening the patterns file, initialize the cache and the cache index position. You’ll use these later (in the <code>__next__()</code> method) as you read lines from the pattern file.
|
||||
<li>After opening the patterns file, initialize the cache. You’ll use this cache later (in the <code>__next__()</code> method) as you read lines from the pattern file.
|
||||
</ol>
|
||||
|
||||
<p>Before we continue, let’s take a closer look at <var>rules_filename</var>. It’s not defined within the <code>__iter__()</code> method. In fact, it’s not defined within <em>any</em> method. It’s defined at the class level. It’s a <i>class variable</i>, and although you can access it just like an instance variable (<var>self.rules_filename</var>), it is shared across all instances of the <code>LazyRules</code> class.
|
||||
|
||||
Reference in New Issue
Block a user