[英]How to convert “\x09” back to tab
I'm reading in a file from Python that has the line: 我正在从Python中读取一行内容:
#separator \x09
How do I convert the \\x09
into a tab character (I'm going to later use this as a delimiter)? 如何将
\\x09
转换为制表符(以后将用作定界符)?
>>> s = r'\x09'
>>> s.decode('unicode_escape')
u'\t'
Or, in Python 3.x (if you have a str
rather than a bytes
, because you can't decode
a str
): 或者,在Python 3.x中(如果您拥有
str
而不是bytes
,因为您无法decode
str
):
>>> s = r'\x09'
>>> s.encode('unicode_escape').decode('unicode_escape')
>>> '\t'
See Python Specific Encodings in the codecs
docs for details. 有关详细信息,请参见
codecs
文档中的Python特定编码 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.