title: How can a Python function create a global object with a name defined in an argument of that function?
body: <p>I want to have a Python function create a global object such that the name of this global object is a name specified as an argument of the function. I know how to create a global object in a function, but I do not know how to create it with a variable name.</p>
  
  <pre><code>def function1():
      global foo
      foo = 3
  
  def function2(nameOfObject):
      exec("global " + nameOfObject)
      bar = 4
  
  function1()
  print foo
  function2("bar")
  print bar
  </code></pre>
  
  <p>The actual use of this type of function shall be to create a global module object and the function shall be used multiple times. Note that I do not want to create an object in the function and then return it to an existing global object.</p>