title: Python: Is it 'proper' to replace global variables with class variables
body: <p>Please be kind with me, I'm a Python beginner :-)</p>
  
  <p>Now, I see that the 'best practice' for writing Python programs would be to wrap the main code inside a 'main' function, and do the <code>if "__main__" == __name__:</code> test to invoke the 'main' function.</p>
  
  <p>This of course results in the necessity of using a series of <code>global</code> statements in the 'main' function to access the global variables.</p>
  
  <p>I wonder if it is more proper (or 'Pythonic', if you will) to gather the global variables into a custom class, say <code>_v</code>, and refer to the variables using <code>_v.</code> prefix instead?</p>
  
  <p>Also, as a corollary question, would that have any negative impact to, let's say, performance or exception handling?</p>
  
  <hr>
  
  <p><strong>EDIT :</strong> The following is the general structure of the program:</p>
  
  <pre><code>paramset = {
      0: { ...dict of params... }
      1: { ...dict of params... }
      2: { ...dict of params... }
      }
  
  selector = 0
  reset_requested = False
  selector_change = False
  
  def sighup_handler(signal,frame):
      global reset_requested
      logger.info('Caught SIGHUP, resetting to set #{0}'.format(new_selector))
      reset_requested = True
      selector = 0
  
  def sigusr1_handler(signal,frame):
      global selector
      new_selector = (selector + 1) % len(paramset)
      logger.info('Caught SIGHUP, changing parameters to set #{0}'.format(new_selector))
      selector = new_selector
      selector_change = True
  
  signal.signal(signal.SIGHUP, sighup_handler)
  signal.signal(signal.SIGUSR1, sigusr1_handler)
  
  def main():
      global reset_requested
      global selector
      global selector_change
      keep_running = True
      while keep_running
          logger.info('Processing selector {0}'.format(selector))
          for stage in [process_stage1, process_stage2, process_stage3]
              err, result = stage(paramset[selector])
              if err is not None:
                  logger.critical('Stage failure! Err {0} details: {0}'.format(err, result))
                  raise SystemError('Err {0} details: {0}'.format(err, result))
              else:
                  logger.info('Stage success: {0}'.format(result))
              if reset_requested:
                  stage_cleanup()
                  reset_requested = False
              else:
                  inter_stage_pause()
                  if selector_change:
                      selector_change = False
                      break
          selector = (selector + 1) % len(paramset)
  </code></pre>