title: Python, sharing mysql connection in multiple functions - pass connection or cursor?
body: <p>I am opening mysql connection in the main function and use that connection in multiple functions called by the main function.</p>
  
  <p><strong>Is there anything wrong with passing cursor from main function instead of passing the connection?</strong></p>
  
  <p>I.e.:</p>
  
  <p><strong>Pass in cursor from main function</strong></p>
  
  <pre><code>def main():
      conn = pymysql.connect(...)
      with conn as cursor:
          func1(cursor)
          func2(cursor)
      conn.close()
  
  def func1(cursor):
      cursor.execute('select ...')
  
  def func2(cursor):
      cursor.execute('insert ...')
  </code></pre>
  
  <p><strong>Pass in connection from main function</strong></p>
  
  <pre><code>def main():
      conn = pymysql.connect(...)
      func1(conn)
      func2(conn)
      conn.close()
  
  def func1(conn):
      with conn as cursor:
          cursor.execute('select ...')
  
  def func2(conn):
      with conn as cursor:
          cursor.execute('insert ...')
  </code></pre>