The data stored in unicode (in database) has to be retrieved and convert into a different form.
The following snippet
def convert(content):
content = content.replace("ஜௌ", "n\[s");
return content;
mydatabase = "database.db"
connection = sqlite3.connect(mydatabase)
cursor = connection.cursor()
query = ''' select unicode_data from table1'''
cursor.execute(query)
for row in cursor.fetchone():
print convert(row)
yields the following error message in convert method.
exceptions.UnicodeDecodeError: 'ascii' codec can't decode byte 0xe0 in position 0: ordinal not in range(128)
If the database content is "ஜௌஜௌஜௌ", the output should be "n\[sn\[sn\[s"
The documentation suggests to use ignore or replace to avoid the error, when creating the unicode string.
when the iteration is changed as follows:
for row in cursor.fetchone():
print convert(unicode(row, errors='replace'))
it returns
exceptions.TypeError: decoding Unicode is not supported
which informs that row is already a unicode.
Any light on this to make it work is highly appreciated. Thanks in advance.
u"example"for your unicode strings in your python script. It's irritating, but Python 2 has two types of strings,unicodeandstr. Not sure about the technical side, these may be 8-bit (encoded e.g. using UTF-8) and 16-bit strings, for example. Plus, you probably want\\[?