The wonderful uses of python encode and decode

高洛峰
Release: 2016-10-19 16:01:12
Original
1783 people have browsed it

String decoding:

There is a string:

'\u4fee\u6539\u8282\u70b9\u72b6\u6001\u6210\u529f'

Want to convert to:

u"u4feeu6539u8282u70b9u72b6u 6001u6210u529f"

can be passed as follows

>> a = '\u4fee\u6539\u8282\u70b9\u72b6\u6001\u6210\u529f'

>>> a.decode('unicode_escape')

u'u4feeu6539u8282u70b9u72b6u6001u621 0u529f'

string converted to 16 Base:

>>> "hello".encode("hex")

'68656c6c6f'


The corresponding one is OK


>>> '68656c6c6f'.decode("hex")

'hello'


You can check the manual to see which codecs are available


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template