title: Why does accessing `self.BASE_DIR` lead to "AttributeError: 'str' object has no attribute 'BASE_DIR'"?
body: <p>Inside a python class the <code>with open</code> line gets:</p>
  <pre><code>Traceback (most recent call last):   
  File &quot;c:\Users\anonymous\Desktop\checker.py&quot;, line 54, in &lt;module&gt;
      print(main.check(&quot;fubk&quot;))   
  File &quot;c:\Users\anonymous\Desktop\checker.py&quot;, line 13, in check
      with open(f&quot;{self.BASE_DIR}\\wordlist.txt&quot;, &quot;r&quot;) as words: 
  AttributeError: 'str' object has no attribute 'BASE_DIR'
  </code></pre>
  <pre><code>class main:
      BASE_DIR = os.path.abspath(os.path.dirname(os.path.abspath(__file__)))
  
      def __init__(self, string, similarity: float = 0.76, BASE_DIR =  BASE_DIR):
          self.string = string
          self.similarity = similarity
          self.BASE_DIR = BASE_DIR
          print(self.DATADIR)
  
      def check(self):
          with open(f&quot;{self.BASE_DIR}\\wordlist.txt&quot;, &quot;r&quot;) as words:
              badwords = words.read().splitlines()
  </code></pre>