title: Python psycopg2 check row exists
body: <p>In Python psycopg2 how can I check if a row exists? </p>
  
  <pre><code>def track_exists(self, track_id):
      cur = self.conn.cursor()
      cur.execute("SELECT fma_track_id FROM tracks WHERE fma_track_id = %s", (track_id,))
      if cur.fetchall() &gt; 0:
          return true
      else:
          return false
  </code></pre>
  
  <p>Currently I am getting </p>
  
  <pre><code>Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  File "mumu.py", line 38, in track_exists
  if cur.fetchall() &gt; 0:
  TypeError: 'NoneType' object has no attribute '__getitem__'
  </code></pre>