title: How to test whether a variable has been initialized before using it?
body: <p>So let's say you've got an application with a variable that you will be creating an instance of when you load it independently (ie when you use <code>if __name__ == '__main__'</code>).  </p>
  
  <p>Also, there is a method that is to be called for when a client imports the application for use within another application.  This method will also instantiate this variable.  </p>
  
  <p>What I want to do is test whether the variable has already been instantiated before defining it (so I don't have to go through the creation of the object twice).  My intuition told me to use <code>if SOME_VARIABLE is not None: #instantiate here</code> but this yields the error </p>
  
  <blockquote>
    <p>local variable 'SOME_VARIABLE'
    referenced before assignment</p>
  </blockquote>
  
  <p>What gives?</p>