title: Copy (from) csv with heades in postgres with python
body: <p>I'm trying to fill a table from CSV files in a python script.</p>
  
  <p>The SQL statement, which follows, runs without error:</p>
  
  <pre><code>COPY registro
  FROM '/home/pablo/Escritorio/puntos/20140227.csv'
  DELIMITER ','
  CSV header;
  </code></pre>
  
  <p>CSV has headers, and using <code>header</code> parameter, it imports without error.</p>
  
  <p>The problem comes when I execute it from my python script. The only way I've found not to try to import the headers is with <code>copy_expert()</code> method. I get no error message but the table is still empty after I run the Python script below.</p>
  
  <p>Any possible clue? Or maybe any other way to copy a table from CSV with headers?</p>
  
  <p>Thanks.</p>
  
  <pre><code>#/usr/bin/env python
  # -*- coding: utf-8 -*-
  import psycopg2
  import os
  import glob
  DSN = "dbname=gps user=postgres host=localhost"
  con = psycopg2.connect(DSN)
  cur = con.cursor()
  my_file = open('/home/pablo/Escritorio/puntos/20140227.csv')
  #This is only a test file, not all the directory
  sql = "COPY registro FROM stdin DELIMITER \',\' CSV header;"
  cur.copy_expert(sql, my_file)
  cur.close()
  con.close()
  </code></pre>