[Tutor] encode unicode strings from pysqlite
Dinesh B Vadhia
dineshbvadhia at hotmail.com
Mon Apr 14 10:31:41 CEST 2008
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')
The print b results in: 99 Cycling Swords ... which is what I want.
But, the print r.encode('utf-8') leaves the strings as unicode strings eg. u'99 Cycling Swords'
Any ideas what might be going on?
Dinesh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080414/39b9cbfc/attachment.htm
More information about the Tutor
mailing list