title: UnboundLocalError: local variable 'conn' referenced before assignment
body: <p>I have an error (shown in title) which occurs when I run this script:</p>
  
  <pre><code>import psycopg2
  
  conn                =  None
  conn_string         = "host='localhost' dbname='localdb' user='someuser' password='abracadabra'"
  
  
  def connectDb():
      if conn is not None:   # Error occurs on this line
          return
  
      # print the connection string we will use to connect
      print "Connecting to database\n -&gt;%s" % (conn_string)
  </code></pre>
  
  <p>conn has global scope, and is assigned to None before being referenced in the function - why the error message?</p>