title: Is there any way to import a variable from a function in another file without using return in Python?
body: <p>I have this pygame code which is divided into multiple files and in one of the files I want to import a variable from a function which is in another file.</p>
  
  <pre><code># gamescreen.py
  highscore = 0
  def game_screen(screen):
      ...
  
      hits = pygame.sprite.spritecollide(player, world_sprites, True, pygame.sprite.collide_mask)
      if len(hits) &gt; 0:
          if score &gt; highscore:
              global highscore
              highscore = score
              state = PLAYAGAIN
      ...
  
      return state
  </code></pre>
  
  <pre><code># playagain.py
  def play_again(screen):
      ...
  
      highscore_texto = font.render('highscore: {0}'.format(highscore), True, (BLACK))
      background.blit(highscore_texto, (30, 25))
      ...
  </code></pre>
  
  <p>Is there any way I can acess that highscore variable in the file playagain.py without having to return it in the game_screen function?</p>
  
  <p>When I tried to return it in the game_screen function like this:</p>
  
  <pre><code>return state, highscore
  </code></pre>
  
  <p>And access it in the playagain.py file like this:</p>
  
  <pre><code>game_screen(screen)[1]
  </code></pre>
  
  <p>It just ran the game_screen function two times, which is not what I want because it messes up my game.</p>