Skip to content

Instantly share code, notes, and snippets.

@ficapy
Created July 27, 2015 10:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ficapy/cc4a974228751942a16d to your computer and use it in GitHub Desktop.
Save ficapy/cc4a974228751942a16d to your computer and use it in GitHub Desktop.
获取文本的unicode编码拼凑字符串
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Author: Ficapy
# Create: '15/7/27'
# from __future__ import unicode_literals
# 兼容2和3
x = '啦啦啦,'
try:
x = unicode(x, 'utf-8') if isinstance(x, str) else x
except:
pass
print(''.join((i.encode('unicode_escape')).decode('utf-8') for i in x).replace('\\u', '%u'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment