#-*-coding:utf-8-*-#python#Xiaodeng#Python Module Marshal (serialization)#from: MldxsImportmarshaldata1= ['ABC', 12, 23,'jb51']data2= {1:'AAA',"b":'dad'}data3= (1,2,4) Output_file= Open ("a.txt",'WB')#serialize the data to a file, note: The file must be opened in binary modemarshal.dump (data1,output_file) marshal.dump (data2,output_file) marshal.dump (data3,output_file) output_ File.close () Input_file= Open ('a.txt','RB')#reading serialized data from a file#data1 = []Data1 =marshal.load (input_file) data2=marshal.load (input_file) data3=marshal.load (input_file)PrintData1#Let's print out the results for the comrades .Printdata2Printdata3Print '------------'outstring= Marshal.dumps (data1)#The marshal.dumps () return is a byte string that is used to write to the fileOpen'OUT.txt','WB'). Write (outstring) File_data= Open ('OUT.txt','RB'). Read () Real_data=marshal.loads (file_data)PrintReal_data
Python Module marshal (serialization)---don't understand.