Py学习  »  Namballa Mukesh  »  全部回复
回复总数  1
4 年前
回复了 Namballa Mukesh 创建的主题 » python将unicode代码值转换为字符串,不带“\u”

你可以这样做: 可以忽略非ASCII字符并编码为ASCII,也可以编码为UTF-8

text = "\u54c8\u54c8\u54c8\u54c8"
utf8string = text.encode("utf-8")
asciistring1 = text.encode("ascii", 'ignore')
asciistring2 = text.encode("ascii", 'replace')

你可以参考 https://www.oreilly.com/library/view/python-cookbook/0596001673/ch03s18.html