Hebrew in idle ans eclipse (Windows)

iu2 israelu at elbit.co.il
Sun Jan 20 05:51:21 EST 2008


On Jan 17, 10:35 pm, "Martin v. Löwis" <mar... at v.loewis.de> wrote:
> > import pymssql
>
> > con =
> > pymssql.connect(host='192.168.13.122',user='sa',password='',database='tempd­b')
> > cur = con.cursor()
> > cur.execute('select firstname, lastname from [users]')
> > lines = cur.fetchall()
>
> > print lines
>
> > or
>
> > print lines[0]
>
> > 'lines' is a list containing tuples of 2 values, for firstname and
> > lastname. The names areHebrewand their code looks different when I'm
> > runnig it fromIDLEthan when running it from Windows shell or
> >eclipse, as I described in my first post.
>
> Ok. Please understand that there are different ways to represent
> characters as bytes; these different ways are called "encodings".
>
> Please also understand that you have to make a choice of encoding
> every time you represent characters as bytes: if you read it from a
> database, and if you print it to a file or to the terminal.
>
> Please further understand that interpreting bytes in an encoding
> different from the one they were meant for results in a phenomenon
> called "moji-bake" (from Japanese, "ghost characters"). You get
> some text, but it makes no sense (or individual characters are incorrect).
>
> So you need to find out
> a) what the encoding is that your data have in MySQL
> b) what the encoding is that is used when printing inIDLE
> c) what the encoding is that is used when printing into
>    a terminal window.
>
> b) and c) are different on Windows; the b) encoding is called
> the "ANSI code page", and c) is called the "OEM code page".
> What the specific choice is depends on your specific Windows
> version and local system settings.
>
> As for a: that's a choice somebody made when the database
> was created; I don't know how to figure out what encoding
> MySQL uses.
>
> In principle, rather than doing
>
>   print lines[0]
>
> you should do
>
>   print lines[0].decode("<a-encoding>").encode("<c-encoding>")
>
> when printing to the console. Furtenately, you can also write
> this as
>
>   print lines[0].decode("<a-encoding>")
>
> as Python will figure out the console encoding by itself, but
> it can't figure out the MySQL encoding (or atleast doesn't,
> the way you use MySQL).
>
> Regards,
> Martin- Hide quoted text -
>
> - Show quoted text -

Thanks for the detailed explanation. I'll try that.



More information about the Python-list mailing list