title: How do you initialize a global variable only when its not defined?
body: <p>I have a global dictionary variable that will be used in a function that gets called multiple times. I don't have control of when the function is called, or a scope outside of the function I'm writing.  I need to initialize the variable only if its not initialized.  Once initialized, I will add values to it.</p>
  <pre><code>global dict
  if dict is None:
      dict = {}
  
  dict[lldb.thread.GetThreadID()] = dict[lldb.thread.GetThreadID()] + 1
  </code></pre>
  <p>Unfortunately, I get</p>
  <pre><code>NameError: global name 'dict' is not defined
  </code></pre>
  <p>I understand that I should define the variable, but since this code is called multiple times, by just saying <code>dict = {}</code> I would be RE-defining the variable every time the code is called, unless I can somehow check if it's not defined, and only define it then.</p>