title: Python: Passing a cursor back from a class for a dbi instance
body: <p>Trying to set up a class that will pass a database cursor back that I can use in various functions. The code below doesn't work</p>
  
  <pre><code>class create_db(object):   
      def __init__(self):
          import psycopg2 as pq
          self.cn = pq.connect('dbname=mydb user=me')
          self.cr = self.cn.cursor()
  </code></pre>
  
  <p>What I'd like to be able to do is</p>
  
  <pre><code>cur = create_db()
  cur.execute('SELECT * FROM table1;')
  </code></pre>
  
  <p>How can I change my code to address that.</p>