简体   繁体   English

如何将“ \\ x09”转换回选项卡

[英]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.

相关问题 python如何将特殊字符串u'\\ x08'u'\\ x09'u'\\ x03'转换为8 9 3 - python how to convert Special string u'\x08' u'\x09' u'\x03' to 8 9 3 打印“ \\ x09”,打印0x20,如何将0x09打印到STDOUT? - Print “\x09”, print 0x20, how to print 0x09 to STDOUT? 如何在 python 中将 (2018-09-05T09:00:06.540486Z) 转换为 (2018-09-05)? - How To Convert (2018-09-05T09:00:06.540486Z) Into (2018-09-05) In python? 如何在 Python 中将 yyyy-mm-dd (2018-08-09) 转换为 Aug09? - How do I convert yyyy-mm-dd (2018-08-09) to Aug09 in Python? 如何将“0 days 00:09:06.633000000”对象转换为分钟/小时/秒? - How to convert "0 days 00:09:06.633000000" object to minutes/hours/seconds? 如何将字符串 2021-09-30_1 转换为日期时间 - How to convert string 2021-09-30_1 to datetime 如何使用 pandas 以小时为单位转换 09:20:05 时间格式? - How to convert 09:20:05 time format in hour using pandas? 如何将数字字符串转换回二进制十六进制(\\ x值)类型? - How to convert a string of numbers back into binary hex (\x values) type? 如何将网格坐标转换回(x,y)? - How can I convert grid coordinates back to (x,y)? 如何使用python strptime和strftime将2017-02-09T09:43:04.216 + 1000等日期时间格式转换为2017年2月9日? - How to convert a datetime format like 2017-02-09T09:43:04.216+1000 to 09-Feb-2017 using python strptime and strftime?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM