Py 3: How to switch application to Unicode strings?

Mark Tolonen metolone+gmane at gmail.com
Wed Jan 20 02:22:06 EST 2010


"Gnarlodious" <gnarlodious at gmail.com> wrote in message 
news:646ab38b-0710-4d31-b9e1-8a6ee7bfa42f at 21g2000yqj.googlegroups.com...
> Well, Python 3 is supposed to be all Unicode by default. I shouldn't
> even need to say
> # coding:UTF-8

Yes, in Python 3, an absence of a 'coding' line assumes UTF-8.

> And, the file is saved as Unicode.

There is no such thing as "saved as Unicode".  Unicode is not an encoding. 
For example, 'ñ' is the Unicode codepoint 241.  This can be stored in a file 
in a number of ways.  UTF-8 is the two bytes 0xc3 0xB1.  UTF-16LE is 0xF1 
0x00.  UTF-16BE is 0x00 0xF1.  latin-1 is the single byte 0xF1.  If your 
editor saves your file in the encoding "latin-1", and you don't use a coding 
line to declare it, Python 3 will throw an error if it finds a non-UTF-8 
byte sequence in the file.

> 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)

Is frameTuple a byte string or Unicode string.  print(repr(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.

Post the simplest, complete source code that exhibits the problem.

-Mark





More information about the Python-list mailing list