Input in Python -



Input in Python -

i have started using python, , got problem non-english (vietnamese in particularly) input. when run code:

# -*- coding: unicode-escape -*- s = raw_input() print(s) s = "hiển thị 15 dòng" print(s)

and terminal type extracly same string, printed like:

hiển thị 15 dòng hi\xe1\xbb\x83n th\xe1\xbb\x8b 15 d\xc3\xb2ng

it create differences in when utilize these 2 type of strings in other function found first 1 didn't work sec 1 did. give me hints? give thanks you!

the problem using # -*- coding: unicode-escape -*- in source file. causes python escape bytes greater 128 in utf-8 representation \xnn hex escape, turning string

'hi\xe1\xbb\x83n th\xe1\xbb\x8b 15 d\xc3\xb2ng'

thus # -*- coding: unicode-escape -*-:

s = "hiển thị 15 dòng"

will become

s = 'hi\\xe1\\xbb\\x83n th\\xe1\\xbb\\x8b 15 d\\xc3\\xb2ng'

the cause of course of study using unicode-escape codec coding; utilize utf-8 instead:

# -*- coding: utf-8 -*-

python input

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -