现在有一个字符串,值就是:
demo = """
[u'\u2019\u2018 \u5fc5\u987b\u4e3a\u5408\u6cd5\u7684\u65e5\u671f\u683c\u5f0f\uff0c\u8bf7\u4f7f\u7528 YYYY-MM-DD \u683c\u5f0f\u3002']
"""
现在我想把字符串里的unicode表示,打印成中文。这个怎么做呢?
就是要这样的效果:
demo = '''
[’‘ 必须为合法的日期格式,请使用 YYYY-MM-DD 格式。]
'''
这两个值之间怎么转换下呢?
Why is this problem again... I have seen it at least ten times QAQ
Of course, it is limited to Python 2, because this kind of string will not be encountered in Python 3.
In fact, your problem should be at the upper level. You shouldn't get a string like this and do what you want with it. You should get the one you want directly.
There is a library called uniout, which can solve some uXXXX display problems in Python 2.
It is strongly recommended to use Python 3, and you will no longer have to worry about Chinese processing.
print(demo[0].encode('gbk').decode('gbk'))
See if this works. If you want to display Chinese in the file, the file encoding format must be supported.