Charset (hopefully for the last time I ask)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gandalf

    Charset (hopefully for the last time I ask)

    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


  • MRAB

    #2
    Re: Charset (hopefully for the last time I ask)

    On Jun 12, 8:04 pm, Gandalf <goldn...@gmail .comwrote:
    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.de code("cp1255")
    print unicode_text
    utf8_text = unicode_text.en code("utf8")
    print utf8_text

    (I believe the codepage 1255 is Hebrew.)

    Comment

    • Gandalf

      #3
      Re: Charset (hopefully for the last time I ask)

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

      any way this is the code I tried

      search=cnrl.Get Value()
      search= search.decode(" cp1255")
      search=search.e ncode("utf8")
      word=''
      category=1
      cur.execute('se lect * 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 :)

      Comment

      • Gandalf

        #4
        Re: Charset (hopefully for the last time I ask)

        OK it did worked!

        I just should have been encoding to cp1255

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


        Thank you!

        you are the best

        Comment

        Working...