title: Reason for globals() in Python?
body: <p>What is the reason of having globals() function in Python? It only returns dictionary of global variables, which are already global, so they can be used anywhere... I'm asking only out of curiosity, trying to learn python.</p>
  
  <pre><code>def F():
      global x
      x = 1
  
  def G():
      print(globals()["x"]) #will return value of global 'x', which is 1
  
  def H():
      print(x) #will also return value of global 'x', which, also, is 1
  
  F()
  G()
  H()
  </code></pre>
  
  <p>I can't really see the point here? Only time I would need it, was if I had local and global variables, with same name for both of them</p>
  
  <pre><code>def F():
      global x
      x = 1
  
  def G():
      x = 5
      print(x) #5
      print(globals()["x"]) #1
  
  F()
  G()
  </code></pre>
  
  <p>But you should never run into a problem of having two variables with same name, and needing to use them both within same scope.</p>