我有一个表格的数据: v = "\xc5\x84"
这是utf-8编码字符“ń”的字节表示。
如何使用变量v打印>>ń<<
我正在使用python 2.7.2
原来变量v包含字符串:
v = "\\xc5\\x84" (双反斜杠)
VS
v = "\xc5\x84" (单个反斜杠)
这本身就是有效的utf-8字符。
I have a data of a form: v = "\xc5\x84"
This is a byte representation of an utf-8 encoded character "ń".
How can I print >>ń<< using variable v?
I'm using python 2.7.2
In original the variable v contained string:
v = "\\xc5\\x84" (double backslashes)
vs
v = "\xc5\x84" (single backslashes)
which is by itself valid utf-8 character.
最满意答案
编辑在我的机器中,输出取决于使用的shell / python,如下所示。 正如Klaus评论的那样,这里的主要角色将是您系统中的区域设置。
>>> v = "\xc5\x84" >>> print v #in pycrust shell python 2.6 Å„ >>> >>> print (v) #in idle python 3.2 Å >>>机器具有以下设置:
>>> import locale >>> locale.getlocale() ('es_ES', 'cp1252')独立于此设置,您可以获得角色
>>> print v.decode('utf-8') ń >>>Edit In my machine the output depends on the shell/python used, as shown below. As commented by Klaus a major actor here would be the locale setting in your system.
>>> v = "\xc5\x84" >>> print v #in pycrust shell python 2.6 Å„ >>> >>> print (v) #in idle python 3.2 Å >>>the machine has the following settings:
>>> import locale >>> locale.getlocale() ('es_ES', 'cp1252')Independently of this setting, you get your character with
>>> print v.decode('utf-8') ń >>>更多推荐
发布评论