# JSON module # import json# dumps method: # JY = {' name ': ' Chinese ', ' price ': 400}# date = Json.dumps (JY) # converts JY to a string that all languages can recognize # with open (' Li Bai ', ' W ', encoding= ' UTF8 ') as f: # write ' Li Bai ' document # F.write (date) # loads method: # with open (' Li Bai ', ' r ', encoding= ' UTF8 ') as f:# date = j Son.loads (F.read ()) # read # print (date) # {' Name ': ' Zhonghua ', ' price ': 400}# print (date[' name ') ') # Chinese # Dump method: # JY = {' Name ': ' Zhonghua ', ' price ': 4000}## with open (' Li Bai ', ' W ', encoding= ' UTF8 ') as f:# date = Json.dump (jy,f) # Write, the dump method omits the F.write () method # Lo Ad method: # with open (' Li Bai ', ' r ', encoding= ' UTF8 ') as f:# date = Json.load (f) # Read, the Load method omits the F.read () method # # print (date) # {' name ': ' Chinese ', ' price ': 4000}# print (date[' price ') # 4000# pickle Module # like JSON, just replace JSON with Pickle, JSON is a string converted to all languages, and Pickle is a conversion String # JSON known as Python cannot convert functions, classes, and Pickle can import pickle# def foo (): # print (' OK ') # Dump method: # with open (' Li Bai ', ' WB ') as F: # pickle needs to write bytes, so use wb# date = Pickle.dump (foo,f) # Load method: # with open (' Li Bai ', ' RB ') as f:# date = Pickle.load (f) # # D Ate () #ok # The function read has noIn the current memory, the Foo function needs to be re-written to the current document, which is seldom used
JSON and pickle modules