diff --git a/examples/plural6.py b/examples/plural6.py
old mode 100644
new mode 100755
index f29293b..945803f
--- a/examples/plural6.py
+++ b/examples/plural6.py
@@ -17,11 +17,9 @@ def build_match_and_apply_functions(pattern, search, replace):
class LazyRules:
rules_filename = 'plural6-rules.txt'
- def __init__(self):
+ def __iter__(self):
self.pattern_file = open(self.rules_filename)
self.cache = []
-
- def __iter__(self):
self.cache_index = 0
return self
diff --git a/iterators.html b/iterators.html
index 573c47b..81b762d 100755
--- a/iterators.html
+++ b/iterators.html
@@ -217,11 +217,9 @@ All three of these class methods, __init__, __iter__,
class LazyRules:
rules_filename = 'plural6-rules.txt'
- def __init__(self):
+ def __iter__(self):
self.pattern_file = open(self.rules_filename)
self.cache = []
-
- def __iter__(self):
self.cache_index = 0
return self
@@ -253,16 +251,17 @@ rules = LazyRules()
class LazyRules:
rules_filename = 'plural6-rules.txt'
- def __init__(self): ①
+ def __iter__(self): ①
self.pattern_file = open(self.rules_filename) ③
- self.cache = [] ②
+ self.cache = [] ②
+ self.cache_index = 0
__init__() method is only going to be called once, when you instantiate the class and assign it to rules.
-__iter__() method is only going to be called once, after you instantiate the class, assign it to rules, and call iter(rules) to create the iterator.
+Before we continue, let’s take a closer look at rules_filename. It’s not defined within the __init__() method. In fact, it’s not defined within any method. It’s defined at the class level. It’s a class variable, and although you can access it just like an instance variable (self.rules_filename), it is shared across all instances of the LazyRules class.
+
Before we continue, let’s take a closer look at rules_filename. It’s not defined within the __iter__() method. In fact, it’s not defined within any method. It’s defined at the class level. It’s a class variable, and although you can access it just like an instance variable (self.rules_filename), it is shared across all instances of the LazyRules class.
>>> import plural6