title: How to fix “AttributeError: __enter__” when using csv.reader(open(..)..)?
body: <p>I get the following error with my code:</p>
  <pre><code>Traceback (most recent call last):
  File &quot;C:\Users\XXX\Sentiment Analysis-vader.py&quot;, line 34, in &lt;module&gt;
      f.printer()
  
  File &quot;C:\Users\XXX\Sentiment Analysis-vader.py&quot;, line 18, in printer
      with csv.reader(open('analyse_' + str(bloombergcode) + '.csv', 'r'), delimiter= &quot;,&quot;,quotechar='|') as q2:
  
  AttributeError: __enter__
  
  Process finished with exit code 1
  </code></pre>
  <p>I used the following code:</p>
  <pre><code>import csv
  from nltk.sentiment.vader import SentimentIntensityAnalyzer
  
  class VaderSentiment:
      def __init__(self, bloomcode):
          self.bloomcode = bloomcode
  
      def print_sentiment_scores(self, sentence):
          self.sentence = sentence
          analyser = SentimentIntensityAnalyzer()
          snt = analyser.polarity_scores(self.sentence)
          print(&quot;{:-&lt;40} {}&quot;.format(self.sentence, str(snt)))
  
      def printer(self):
          bloombergcode = self.bloomcode
          with csv.reader(open('analyse_' + str(bloombergcode) + '.csv', 'r'), delimiter= &quot;,&quot;,quotechar='|') as q2:
              for line in q2:
                  for field in line:
                      print_sentiment_scores(field)
  
  for code in ('AAPL', 'NFLX'):
      f = VaderSentiment(code)
      f.printer()
      time.sleep(1)
  </code></pre>
  <p>I already saw some other similar problems (<a href="https://stackoverflow.com/questions/46273154/python-json-with-returns-attributeerror-enter">Python Json with returns AttributeError: __enter__</a>) but the solutions do not work on my problem.</p>
  <p>Does anyone see the problem?</p>