Tag:load Verification Code utf-8 pytho int Default data memory and
#-*-Coding:utf-8-*-import Random as Rd #验证码import Hashlib as HSL #MD5加密import pickle,json #pickle与json序列化 #print Rd.rand int (1,5) #print Help (range) #print Help (Rd.randint) #随机生成6位验证码: code = []for i in Range (1,7): if i = = Rd.randint (1,6): Code.append (str (i)) Else:code.append (Chr (Rd.randint (65,90)) print '. Join (code) #MD5加密, cannot be reversed, real MD5 () positive solution matches Hashtest = HSL.MD5 () hashtest.update (' admin ') print hashtest.hexdigest () when verifying that the user is logged in () #pickle序列化与反序列化 And the difference between the JSON and the "" "Pickle and Json1.pickle is dedicated to Python, JSON is supported in almost all programming languages, and data memory interactions between different languages are the same for JSON-based 2.pickle and JSON in Python, pickle basically all data types in Python can be serialized JSON can only serialize regular lists, dictionaries, etc. 3.pickle serialized data is not readable by default (artificially indistinguishable), but JSON serialization can be visualized (readable) "" "Dict_pick = {' name ': ' Binguo ', ' age ': 27, ' Blogurl ': ' http://blog.csdn.net/binguo168 '}dict_json = {' Company ': ' China ', ' hobby ': ' study '} #序列化result1 = Pickle.dumps (dict_pick) result2 = Json.dumps (dict_json) Print result1print Result2with open (' E:/pickleresult.txt ', ' W ' ) as File_pickle:pickle.dump (Dict_pick, File_picKle) #序列化到文件with file (' E:/pickleresult.txt ', ' R ') as Read_pickle:print pickle.load (read_pickle) #从文件反序列化回来 #反序列化prin T pickle.loads (RESULT1) print json.loads (RESULT2)
Python learning Experience (v) random generation of CAPTCHA, MD5 encryption, pickle and JSON serialization and deserialization