有个字符串:
'\\u4fee\\u6539\\u8282\\u70b9\\u72b6\\u6001\\u6210\\u529f'
想转换为:
u"\u4fee\u6539\u8282\u70b9\u72b6\u6001\u6210\u529f"
可以通过如下
>>> a = '\\u4fee\\u6539\\u8282\\u70b9\\u72b6\\u6001\\u6210\\u529f'
>>> a.decode('unicode_escape')
u'\u4fee\u6539\u8282\u70b9\u72b6\u6001\u6210\u529f'
字符串转换为16进制:
>>> "hello".encode("hex")
'68656c6c6f'
相应的还可以
>>> '68656c6c6f'.decode("hex")
'hello'
可以检查下手册,看看哪些codec可用
Copyright © 2019- 7swz.com 版权所有 赣ICP备2024042798号-8
违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务