title: Python Project Structure - multiple files and modules
body: <p>I was used to PHP where a global variable will be available on the whole project, and including/requiring a PHP file is pretty much just like 'injecting' it's code lines on that spot: the whole thing would be 'seen' as a single file, and all vars would be instinctively acessed.</p>
  
  <p>Python works in a different way and I'd like to know good practices in order to make a large project more manageable by splitting it into files...</p>
  
  <p>So lets say I have a file called configs.py that's something like:</p>
  
  <pre><code>FRAME_DURATION = int(1000 / 25)
  SCREEN_SIZE = 500
  
  LIGHT_GREY  = (190,190,190)
  RED = (255,0,0)
  GREEN = (0,255,0)
  YELLOW = (255,255,0)
  #etc...
  </code></pre>
  
  <p>Then, on the Main.py file I could do something like:</p>
  
  <pre><code>import pygame
  from configs import *
  
  pygame.init()   
  SCREEN = pygame.display.set_mode((SCREEN_SIZE, SCREEN_SIZE),1)
  SCREEN.fill(LIGHT_GREY)
  
  run = True
  while run:
      pygame.time.delay(FRAME_DURATION )
  
      #HERE I'M SUPPOSED TO CHECK THE KEYBOARD AND MOUSE EVENTS
  
      pygame.display.update()
  
  pygame.quit()
  </code></pre>
  
  <p>And this work just fine since we're handling only variables. But if i want to make the event listener into another separate file I run into some 'troubles'. Let's say I want a file with all my functions. I'll name it actions.py and it contains the following function:</p>
  
  <pre><code>def checkEvents():
      for event in pygame.event.get():
          if event.type == pygame.QUIT:
              run = False
  
          if event.type == pygame.KEYDOWN:
              if event.key == pygame.K_ESCAPE:
                  run = False
              if event.key == pygame.K_r:
                  pass
  </code></pre>
  
  <p>If I want to be able to call the checkEvents() function inside the main.py file I get a NameError sinceit doesn't recognizes pygame module inside the actions.py file.</p>
  
  <p>I can't seem to make it work: if i import it on both files (which i know is sup-optimal), the game launches but keys and exit key don't do nothing. I guess the checkEvents() function is listening to another instance of pygame?</p>
  
  <p>Anyway, I'd like to know if there's a way to make modules 'globally available'... Importing it once on main file and using it on the whole project, including inside other imported custom modules?</p>
  
  <p>The final result should look something like this:</p>
  
  <pre><code>import pygame
  from configs import *
  import actions
  
  pygame.init()   
  SCREEN = pygame.display.set_mode((SCREEN_SIZE, SCREEN_SIZE),1)
  SCREEN.fill(LIGHT_GREY)
  
  run = True
  while run:
      pygame.time.delay(FRAME_DURATION )
  
      actions.checkEvents()
  
      pygame.display.update()
  
  pygame.quit()
  </code></pre>