python: json,base64 的使用
JSON
1. import json
2. json.dumps() json obj => string
3. json.load() string => json obj
1. import json
2. json.dumps() json obj => string
3. json.load() string => json obj
Base64
python: json,base64 的使用
Base64
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
Python代码 import base64 import StringIO a = "this is a test" b = base64.encodestring(a) # 对字符串编码 print b print base64.decodestring(b) # 对字符串解码 c = StringIO.StringIO() c.write(a) d = StringIO.StringIO() e = StringIO.StringIO() c.seek(0) base64.encode(c, d) # 对StringIO内的数据进行编码 print d.getvalue() d.seek(0) base64.decode(d, e) # 对StringIO内的数据进行解码 print e.getvalue() a = "this is a +test" b = base64.urlsafe_b64encode(a) # 进行url的字符串编码 print b print base64.urlsafe_b64decode(b) |

做自己喜欢做的,跟家人同等重要