Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何转换\x09";返回选项卡_Python_String_Character Encoding_Decoding - Fatal编程技术网

Python 如何转换\x09";返回选项卡

Python 如何转换\x09";返回选项卡,python,string,character-encoding,decoding,Python,String,Character Encoding,Decoding,我正在从Python中读取一个文件,其中有一行: #separator \x09 如何将\x09转换为制表符(稍后我将使用它作为分隔符) 或者,在Python3.x中(如果您有一个str而不是bytes,因为您不能解码astr): 有关详细信息,请参见编解码器文档中的 或者,在Python3.x中(如果您有一个str而不是bytes,因为您不能解码astr): 有关详细信息,请参见编解码器文档中的 >>> s = r'\x09' >>> s.decode('

我正在从Python中读取一个文件,其中有一行:

#separator \x09
如何将
\x09
转换为制表符(稍后我将使用它作为分隔符)

或者,在Python3.x中(如果您有一个
str
而不是
bytes
,因为您不能
解码
a
str
):

有关详细信息,请参见
编解码器
文档中的

或者,在Python3.x中(如果您有一个
str
而不是
bytes
,因为您不能
解码
a
str
):

有关详细信息,请参见
编解码器
文档中的

>>> s = r'\x09'
>>> s.decode('unicode_escape')
u'\t'
>>> s = r'\x09'
>>> s.encode('unicode_escape').decode('unicode_escape')
>>> '\t'