4

I know this is a quite common issue, but after reading some of the forum threads, read some articles, still haven't found a solution , and i'm quite sure it's a simple one. The problem is that i have a code with some hebrew letters that are inserted by the user (raw_input). as long as I ask to print what the user typed it's ok. once i get it into a list it gives me the bytes version of probably UTF-8 (not sure). I can't seem to be able to decode it, and i think the reason is not knowing what encoding is done in the actual console. The below is simply an exercise for me to understand how to work with hebrew. I also tried to place a "u" before a list item.. didnt work or i didnt have the right syntax to handle in a list.

I am using Python 2.7.8 and the Python IDLE editor. My OS - win7 64bit This is the code

#!/usr/bin/python
# -*- coding: utf8 -*-    
word=raw_input('בחר מילה')
print word
loc=[]
for i in word:
    print i
    print type(i)


word=word+i
loc.append(i)

print loc

This is the output

בחר מילהשמש
שמש
ש
<type 'str'>
מ
<type 'str'>
ש
<type 'str'>
['\xf9', '\xee', '\xf9']

How can switch the list items into hebew letter? Thanks for the help

Jumbalaya
  • 39
  • 2

1 Answers1

0

Taken from here

try to use:

import sys
text= raw_input().decode(sys.stdin.encoding)

Not text should be unicode, and as general rule, convert the input the unicode as early as possible.

Community
  • 1
  • 1
eran
  • 6,731
  • 6
  • 35
  • 52
  • Hi eran and thanks. I tried it, and now it does turn it into unicode with the folloiwng representation [u'\u05e9', u'\u05de', u'\u05e9']. so the question now is how do i make it "human like". Thanks for your quick reply – Jumbalaya Oct 19 '14 at 04:44
  • I meant how do i pull it as a Hebrew letter from the list. once i printed an item from the list i noticed that while it is written in Unicode within the list , the output is a Hebrew letter - so I am fine. thanks alot for the help Eran – Jumbalaya Oct 19 '14 at 12:17