[英]How to get Unicode input from user in Python?
这是代码: varUnicode = input('\\tEnter your Unicode\\n\\t>') print('\\u{}\u0026#39;.format(varUnicode))
我想从用户那里获取 unicode 输入并打印字符。 在上面的代码中,python 给了我一个错误。
\\u\u003c/code>是在字符串文字中识别的转义序列:
仅在字符串文字中识别的转义序列是:
Escape Meaning Notes Sequence \\N{name} Character named name in the Unicode database (4) \\uxxxx Character with 16-bit hex value xxxx (5) \\Uxxxxxxxx Character with 32-bit hex value xxxxxxxx (6)
笔记:
在 3.3 版更改: 添加了对名称别名 1 的支持。
正好需要四个十六进制数字。
任何 Unicode 字符都可以通过这种方式进行编码。 正好需要八个十六进制数字。
用
varUnicode = input('\tEnter your Unicode\n\t>')
print('\\u{}'.format(varUnicode.zfill(4)).encode('raw_unicode_escape').decode('unicode_escape'))
或(也许更好)
varUnicode = input('\tEnter your Unicode\n\t>')
print('\\U{}'.format(varUnicode.zfill(8)).encode('raw_unicode_escape').decode('unicode_escape'))
您需要在字符串前添加u
以将其视为 Unicode。 print(u'\Р')
将给出P
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.