samedi 13 février 2016

portugese characters in DBsqlite and python parsing not recognised

I got a database in DBsqlite.in this DBsqlite database I have have a records containing portugese text like "Hiper-radiação simétrica periocular bem delimitada, homogênea."

and the characters like ç ã é ê don't parse right in my python script.

While normal english text is doing it perfectly.

In my terminal window (I use a mac) the

I know it has something do to with the encoding. but the code still doesn't recognise portugese.

my sample code:

# -*- coding: UTF-8 -*-

import xml.etree.ElementTree as ET
import sqlite3

#open a database connection to the database translateDB.sqlite
conn = sqlite3.connect('translateDB.sqlite')

#prepare a cursor object using cursus() method
cursor = conn.cursor()

#test input
# this doesn't work
text = ('Hiper-radiação simétrica periocular bem delimitada,   homogênea')

# this does work in english
#text = ('Well delimited, homogeneous symmetric periocular hyper-    radiation.')

# Execute SQL query using execute() method.
cursor.execute('SELECT * FROM translate WHERE L2_portugese=?', (text,))

# Fetch a single row using fetchone() method and display it.
print cursor.fetchone()

# Disconnect from server
conn.close()

any tips & tricks are greatly appreciated. Ron

Aucun commentaire:

Enregistrer un commentaire