title: AttributeError: 'function' object has no attribute error when trying to access a variable from a function
body: <p>If been working on a twitter bot for a while now, just for fun, but I've been stuck with this single problem. Sometimes it works, sometimes it does not. Here is the code:</p>
  <pre><code>def teste():
      tweets = api.home_timeline(2, read_id(FILE_NAME), tweet_mode = 'extended')
      print('Setup is ok!')
      for tweet in reversed(tweets):
          if 'carente' in tweet.full_text.lower():
              print(str(tweet.id) + ' - ' + tweet.full_text)
              api.retweet(tweet.id)
              store_the_id(FILE_NAME, tweet.id)
              teste.x = 1
          elif 'carente' not in tweet.full_text.lower():
              teste.x = 0
          else:
              print('Error no sistema alguem me desconfiguro')
  
  def tweet_timer():
      if time.gmtime().tm_min == '10':
          api.update_status(f'Farid esteve carente {y} vezes')
      else:
          return
  
  while True:
      teste()
      with open('number.txt', 'r') as f:
          read = f.readline
          z = int(read())
      y = z + teste.x
      print(y)
      with open('number.txt', 'w') as f:
          write = f.write(str(y))
          write
      tweet_timer()
      time.sleep(40) 
  </code></pre>
  <p>I'm trying access the <strong>teste.x</strong> variable out of the function, but when I do at the <strong>y = z + teste.x</strong> it gives the following error:</p>
  <pre><code>Traceback (most recent call last):
    File &quot;c:\Users\fredg\Desktop\Programação\Python\Twitter Bot\Website\Word.py&quot;, line 69, in &lt;module&gt;
      y = z + teste.x
  AttributeError: 'function' object has no attribute 'x'
  </code></pre>