I'm reading in a file from Python that has the line:
#separator \x09
How do I convert the \\x09
into a tab character (I'm going to later use this as a delimiter)?
>>> 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
):
>>> s = r'\x09'
>>> s.encode('unicode_escape').decode('unicode_escape')
>>> '\t'
See Python Specific Encodings in the codecs
docs for details.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.