Then, how should I do it?
I read a byte string from sys.stdin which needs to converted to unicode
string for further processing. I cannot just remove the decode statement and
proceed?
This is it what it looks like:
for line in sys.stdin:
line = line.decode('utf-8').strip()
if line == '<page>': #do something here
elsif #do something here
If I remove the decode statement, line == '<page>' never gets true.
--Akhil
Piet van Oostrum wrote:
>
>>>>>> akhil1988 <[email protected]> (a) wrote:
>
>>a> ok!
>>a> I got the indentation errors fixed. Bu I get another error:
>
>>a> Traceback (most recent call last):
>>a> File "./temp.py", line 484, in <module>
>>a> main()
>>a> File "./temp.py", line 476, in main
>>a> line.decode('utf-8').strip()
>>a> AttributeError: 'str' object has no attribute 'decode'
>
>>a> I am using Python3.1
>
> In Python 3 you can't decode strings because they are Unicode strings
> and it doesn't make sense to decode a Unicode string. You can only
> decode encoded things which are byte strings. So you are mixing up byte
> strings and Unicode strings.
> --
> Piet van Oostrum <[email protected]>
> URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
> Private email: [email protected]
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
--
View this message in context:
http://www.nabble.com/UnicodeEncodeError%3A-%27ascii%27-codec-can%27t-encode-character-u%27%5Cxb7%27-in-position-13%3A-ordinal-not-in-range%28128%29-tp24509879p24525761.html
Sent from the Python - python-list mailing list archive at Nabble.com.
--
http://mail.python.org/mailman/listinfo/python-list