unicode - Python character handling in terminal -
I am in an interactive Pyren 2.7 terminal (Terminal Default Output "UTF-8"). I have a string from the Internet, it has a
gt; & Gt; & Gt; One u'm \ xfcssen '& gt; & Gt; & Gt; A [1] u '\ xfc'
I wonder why its value is ü
so I tried
& Gt; & Gt; & Gt; Print (A) Mucin & gt; & Gt; & Gt; Printed (a [1]) ü
works with purpose.
So my first question is, print
which is missing if I just a
?
And get out of curiosity: Why is it that I get another output for the following in the same Python terminal session?
& gt; & Gt; & Gt; "Ü" '\ xc3 \ xbc' & gt; & Gt; & Gt; Print "ü" traceback (most recent call final): File "& lt; stdin>", line 1, & lt; Module & gt; File "/usr/lib/python2.7/codecs.py", line 351, in writing data, consumption = self.encode (object, self.errors) Unicodecode error: 'ascii' codec does not decode by 0xc3 in position 0 Could: Not Sort Category (128) & gt; & Gt; & Gt; Print u "ü" ü
You have to understand how Python is stored in different data types The job that expects which input is all this much misleading and it depends on your LOCALE setting of your terminal.
The following links can help to reduce confusion:
All str
objects such as "my string"
to 8bit Is stored as per your case in your case '\ xc3 \ xbc'
UMLA-U's UTF8 representation is in the form of a str
object
Unicode
for objects, Python uses a 16bit or 32bit integer to store the dragon string.
The print
function is now expected to be in the form of an input of str
, which is why the following tasks
< Code> & gt; & Gt; & Gt; Print '\ xc3 \ xbc' ü
to convert UILAUT -U from a str
to a Unicode
object You must specify that the string is in UTF8 representation before you convert it to a unicode
object
& gt; & Gt; & Gt; Unicode ('\ xc3 \ xbc'.decode (' utf8 '))' \ xfc '
Comments
Post a Comment