AttributeError: instance has no attribute
<p>This seems to be a common error in Python, and I've found many instances of people asking about similar but spent the last (long amount of time) trying those solutions where they seemed applicable and have had no luck, so resorting to asking to find out what I'm missing.  </p>

<p>I'm receiving <strong>AttributeError: WebHandler instance has no attribute 'search_str'</strong> </p>

<p>It seems to be this one particular method, any time I call any of the class variables set in <strong>___init___</strong> from this method I receive this error.  I've extracted it to a test file as a simple function rather than a class method and it works fine, and I've tried re-indenting everything a few times to make sure it wasn't that, so I'm at a loss on this.</p>

<p>I'm using Python 2.7 and TextWrangler if either of these are helpful (TextWrangler hasn't given me any problems in 3 years like this, but figured anything should be included)</p>

<pre><code>import requests
import re

class WebHandler():

    def ___init___(self):
        self.urllist = []
        self.search_str = re.compile(r'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&amp;+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', re.I|re.M)

    def set_urls(self, test, data):
        for line in test[11:]:
            if (("even" in line) or ("odd" in line)):
                match = re.search(self.search_str, line)
            self.urllist.append(match.group(0))
</code></pre>

<p>Another thing I tried, if I copy the attributes from <strong>___init___</strong> and simply make them local to <strong>set_urls()</strong> and call them without <strong>self</strong> that way it works properly and doesn't throw any errors, which is confusing me even more.</p>

<p>No idea what I'm missing.  Thanks!</p>

<p>This that you have:</p>

<pre><code>def ___init___(self):
</code></pre>

<p>Is not the same as this that gets called when an object is instantiated:</p>

<pre><code>def __init__(self):
</code></pre>

<p>The difference is that you have <em>three</em> underscores on either side of <code>init</code>, while two are required.</p>

python python-2.7 oop attributeerror