Py 3: How to switch application to Unicode strings?

Stephen Hansen apt.shansen at gmail.com
Tue Jan 19 23:45:11 EST 2010


On Tue, Jan 19, 2010 at 8:16 PM, Gnarlodious <gnarlodious at gmail.com> wrote:

> Well, Python 3 is supposed to be all Unicode by default. I shouldn't
> even need to say
> # coding:UTF-8
>
> And, the file is saved as Unicode.
>
> There are many mentions of this error found by Google, but none seen
> to clearly say what the problem is or how to fix it.
>
> FYI, the problem line says:
>
> cursor.execute('insert into Data values
> (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', frameTuple)
>
> and one of the strings in the tuple contains a character like 'ñ'.
> I have a version of the SQLite editor that works as expected in a
> browser, I don't know why.
>
>
But is it a -unicode- string, or a -byte- string? Print it with repr(). By
that error, it seems like its a bytestring. So you read it or got it from a
source which provided it to you not as unicode. In that case, find out what
the encoding is-- and decode it.

after = before.decode("utf8")

Python 3 is not 'all unicode'; or 'by default'. Python 3 has a firm line in
the sand. Everything is either explicitly a byte string (bytes) or
explicitly a unicode string (str).

--S
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100119/01fef7e5/attachment-0001.html>


More information about the Python-list mailing list