Skip to content

Commit bf93fbb

Browse files
committed
新增unicode编码后的汉字的解析
1 parent 8744b1d commit bf93fbb

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

Linux.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -383,10 +383,7 @@ $ google-chrome --proxy-server="socks5://192.168.2.157"
383383

384384
ubuntu 解压 RAR
385385
```
386-
# 安装
387-
$ sudo apt-get install rar
388-
# 解压
389-
$ rar x FileName.rar
386+
$ sudo apt-get install p7zip-rar
390387
```
391388

392389
统计当前目录下指定后缀名的文件总个数命令

tools/convert.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,31 @@ def hex_to_bytes(string):
2121
return bytes(tmp)
2222

2323

24+
def test_unescape():
25+
# unicode编码后的汉字的解析
26+
str_xx = '加入到"我的书目选单"中'
27+
from HTMLParser import HTMLParser
28+
h = HTMLParser()
29+
print h.unescape(str_xx)
30+
31+
32+
def test_unicode():
33+
a = '\u6211\u6765\u4e86'
34+
print a.decode('raw_unicode_escape') # 我来了
35+
36+
# =============
37+
# 通用转换方法:
38+
39+
# python 2.x str 转 unicode:
40+
# str_string.decode('original_encoding')
41+
print repr('我来了'.decode('utf-8')), '我来了'.decode('utf-8')
42+
43+
# unicode 转 str:
44+
# unicode_string.encode('target_encoding')
45+
print repr(u'\u6211\u6765\u4e86'.encode('utf-8')), u'\u6211\u6765\u4e86'.encode('utf-8') # 每个汉子占3个字节
46+
print repr(u'\u6211\u6765\u4e86'.encode('GBK')), u'\u6211\u6765\u4e86'.encode('GBK') # 每个汉子占2个字节
47+
48+
2449
def test():
2550
"""
2651
转换测试
@@ -49,6 +74,8 @@ def test():
4974
test()
5075
print system_to_decimal('000000001b2025f6', 16)
5176
print system_to_decimal('0001000100010001', 2)
77+
test_unescape()
78+
test_unicode()
5279

5380

5481
"""

tools/mysql.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def get_count_by_sql(self, sql=None):
127127

128128
def get_rows_by_sql(self, sql=None):
129129
"""
130-
获取记录总数
130+
获取记录
131131
:return:
132132
"""
133133
if self.is_conn_open() is False:

0 commit comments

Comments
 (0)