title: Python's 'with' statement versus 'with .. as'
body: <p>Having just pulled my hair off because of a difference, I'd like to know what the difference <em>really</em> is in Python 2.5.</p>
  
  <p>I had two blocks of code (<code>dbao.getConnection()</code> returns a MySQLdb connection).</p>
  
  <pre><code>conn = dbao.getConnection()
  with conn:
      # Do stuff
  </code></pre>
  
  <p>And</p>
  
  <pre><code>with dbao.getConnection() as conn:
      # Do stuff
  </code></pre>
  
  <p>I thought these would have the same effect but apparently not as the <code>conn</code> object of the latter version was a <code>Cursor</code>. Where did the cursor come from and <em>is</em> there a way to combine the variable initialization and with statement somehow?</p>