Charset (hopefully for the last time I ask)

G

Gandalf

now I understand my problem better so their is a good chance you
manage to help me.

I have a SQlite database full with ANSI Hebrew text , and program that
uses WXpython
Now, I use a- 'wx.TextCtrl' item to receive input from the user, and
when I try to search the database he don't understand this chars.

it's quite reasonable consider the fact the program set to work on
UTF-8 charset, except for:

1. it doesn't work when I delete the charset too

2. when I try to use function like decode and encode it output error
like this:
ascii' codec can't encode characters in position 0-4: ordinal not in
range(128)
ascii' codec can't encode characters in position 0-2: ordinal not in
range(128)

3. I don't know how to translate my DB from ANSI to UTF-8

4. when I don't use the user WX items input I can change my editor
charset to ansi and it works fine


Thank you all
 
M

MRAB

now I understand my problem better so their is a good chance you
manage to help me.

I have a SQlite database full with ANSI Hebrew text , and program that
uses WXpython
Now, I use a- 'wx.TextCtrl' item to receive input from the user, and
when I try to search the database he don't understand this chars.

it's quite reasonable consider the fact the program set to work on
UTF-8 charset, except for:

1. it doesn't work when I delete the charset too

2. when I try to use function like decode and encode it output error
like this:
ascii' codec can't encode characters in position 0-4: ordinal not in
range(128)
ascii' codec can't encode characters in position 0-2: ordinal not in
range(128)

3. I don't know how to translate my DB from ANSI to UTF-8

4. when I don't use the user WX items input I can change my editor
charset to ansi and it works fine

Thank you all

Have you tried something like:

unicode_text = text_from_db.decode("cp1255")
print unicode_text
utf8_text = unicode_text.encode("utf8")
print utf8_text

(I believe the codepage 1255 is Hebrew.)
 
G

Gandalf

Yes, it is 1255 it's surprising you know that.

any way this is the code I tried

search=cnrl.GetValue()
search= search.decode("cp1255")
search=search.encode("utf8")
word=''
category=1
cur.execute('select * from hebrew_words where word like ?',
[''+search+''])

this is the error it send me :

'ascii' codec can't encode characters in position 0-1: ordinal not in
range(128)

have any idea?

Thank you for trying any way. it worms my Jewish art :)
 
G

Gandalf

OK it did worked!

I just should have been encoding to cp1255

search=cnrl.GetValue()
search= search.encode("cp1255")
cur.execute('select * from hebrew_words where word like ?',
['%'+search+'%'])


Thank you!

you are the best
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top