Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>keys=("unknown1", 'county', 'businessName', 'address1', 'city1', 'zip1', 'phone1', 'Email1', 'approvalstatus', 'date1','date2', 'typeofConstruct', 'typeofBiz', 'unknown2', 'unknown3', 'unknown4', 'unknown5', 'unknown6', 'BizName2', 'Address2', 'City2', 'Zip2', 'Country2', 'Phone2', 'Email2', 'Phone3') args=[tuple(i[key].decode('utf-8') for key in keys) for row in dr] sql='INSERT INTO t ({f}) VALUES ({p})'.format( f=','.join(keys), p=','.join(['?']*len(keys))) curs.executemany(sql, args) </code></pre> <hr> <p>Or, for a more robust solution, you could use UnicodeDictReader, slightly modified version of <a href="http://docs.python.org/library/csv.html#examples" rel="nofollow">UnicodeReader (from the csv docs)</a> to return rows as dicts with unicode values:</p> <pre><code>class UTF8Recoder: """ Iterator that reads an encoded stream and reencodes the input to UTF-8 """ def __init__(self, f, encoding): self.reader = codecs.getreader(encoding)(f) def __iter__(self): return self def next(self): return self.reader.next().encode("utf-8") class UnicodeDictReader: def __init__(self, f, dialect=csv.excel, encoding="utf-8", **kwds): f = UTF8Recoder(f, encoding) self.reader = csv.DictReader(f, dialect=dialect, **kwds) def next(self): row = self.reader.next() return dict((key,unicode(val, "utf-8")) for key,val in row.iteritems()) def __iter__(self): return self with open('HR_plan_review.csv', 'rb') as infile: dr = UnicodeDictReader(infile, delimiter = ',') </code></pre> <p>The code I posted above could still be used, just change</p> <pre><code>args=[tuple(i[key].decode('utf-8') for key in keys) for row in dr] </code></pre> <p>to </p> <pre><code>args=[tuple(i[key] for key in keys) for row in dr] </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload