[Tutor] Tutor Digest, Vol 50, Issue 43
kinuthia muchane
muchanek at gmail.com
Mon Apr 14 16:39:06 CEST 2008
>
> Message: 1
> Date: Mon, 14 Apr 2008 01:31:41 -0700
> From: "Dinesh B Vadhia" <dineshbvadhia at hotmail.com>
> Subject: [Tutor] encode unicode strings from pysqlite
> To: <tutor at python.org>
> Message-ID: <BAY109-DAV1ACDF00838044582FC20CA3E80 at phx.gbl>
> Content-Type: text/plain; charset="iso-8859-1"
>
> Here is a program that SELECT's from a pysqlite database table and encode's the returned unicode strings:
>
> import sys
> import os
> import sqlite3
>
> con = sqlite3.connect("testDB.db")
> cur = con.cursor()
>
> a = u'99 Cycling Swords'
> b = a.encode('utf-8')
> print b
>
> q = '%wor%'
> limit = 25
> query = "SELECT fieldB FROM testDB WHERE fieldB LIKE '%s' LIMIT '%s'" %(q, limit)
> for row in cur.execute(query):
> r = str(row)
> print r.encode('utf-8')
Why not change this to:
> for row in cur.execute(query):
> for item in row:
> print item.encode('utf-8')
which will return a string ?
Kinuthia.
More information about the Tutor
mailing list