title: NameError: name 'tweets_source' not defined | But it has default value
body: <p>I have this code:</p>
  
  <pre><code>import json
  
  class TweetFormatter():
  
      def __init__(self, source_file='twitter_data.txt'):
          self.tweets_source = source_file
  
      def convert2json(self, tweets_source=None):
          tweets_data = []
          if tweets_source is None:
              if self.tweets_source is not None:
                  tweets_source = self.tweets_source
              else:
                  raise ValueError("You need to specify a file")
  
          with open(tweets_source, "r") as tweets_file:
              for line in tweets_file:
                  try:
                      tweet = json.loads(line)
                      tweets_data.append(tweet)
                  except:
                      continue
          return tweets_data
  </code></pre>
  
  <p>And I'm calling convert2json method like:</p>
  
  <pre><code>formatter = TweetFormatter('twitter_data.txt')
  tweets = formatter.convert2json()
  </code></pre>
  
  <p>Python throws error:</p>
  
  <pre><code>Traceback (most recent call last):
  File "analysis.py", line 12, in &lt;module&gt;
      tweets = formatter.convert2json()
  File "/home/azaroma/analisis-machismo/app/tweet_formatter.py", line 11, in convert2json
  with open(tweets_source, "r") as tweets_file: 
  NameError: name 'tweets_source' is not defined
  </code></pre>
  
  <p>I believe that <code>tweets_source</code> should be defined because it has a default value. Also, if a i call <code>formatter.convert2json('twitter_data.txt')</code> python throws:</p>
  
  <pre><code>Traceback (most recent call last):
  File "analysis.py", line 12, in &lt;module&gt;
  tweets = formatter.convert2json('twitter_data.txt')
  TypeError: convert2json() takes 1 positional argument but 2 were given
  </code></pre>
  
  <p>This has to be something really simple but I can't figure it out.</p>