title: python 'with' statement, should I use contextlib.closing?
body: <pre><code>from contextlib import closing
  
  def init_db():
      with closing(connect_db()) as db:
          with app.open_resource('schema.sql') as f:
              db.cursor().executescript(f.read())
          db.commit()
  </code></pre>
  
  <p>This is from flask tutorial Step 3(<a href="http://flask.pocoo.org/docs/tutorial/dbinit/#tutorial-dbinit" rel="noreferrer">http://flask.pocoo.org/docs/tutorial/dbinit/#tutorial-dbinit</a>). And I'm little curious about the line 4 of that. </p>
  
  <p>Must I import and use that 'contextlib.closing()'  method? </p>
  
  <p>When I've learned about <strong>with</strong> statement, many articles said that it closes file automatically after process like below.(same as Finally: thing.close())</p>
  
  <pre><code>with open('filename','w') as f:
      f.write(someString);
  </code></pre>
  
  <p>Even though I don't use that contextlib.closing() like below, What's difference?
  It's from version 2.7.6, Thank you.</p>
  
  <pre><code>def init_db():
      with connect_db() as db:
          with app.open_resource('schema.sql') as f:
              db.cursor().executescript(f.read())
          db.commit()
  </code></pre>