title: Closing cursor and connection with Python and MySQLdb
body: <p>I have a simple web.py-based app that uses MySQLdb. I have a class that handles database operations like so:</p>
  
  <pre><code>class db():
     def __init__(self):
         db = MySQLdb.connect(host='mysql.server', user='user', passwd='pass', db='app')
         self.cur = db.cursor()
  
     def get_data(self):
         sql = "SELECT * FROM foobar"
         self.cur.execute(sql)
         rs = self.cur
         r.fetchall()
         return rs
  </code></pre>
  
  <p>I instantiate the class like so <code>DB = db()</code>. Then, in another class, I will refer to it.</p>
  
  <pre><code>class bleh()
     def blarg():
        DB.get_data()
  </code></pre>
  
  <p>With something like this, where would I close the cursor and connection? Or am I approaching this completely wrong?</p>