First, the module
The module is a written function placed in a file, namely the Py file
Types of modules:
① built-in module: When you install the Python interpreter, it's loaded.
② third-party modules, extension modules: Not necessarily not the built-in module is not important, according to user requirements installation and use
③ Custom module: Self-written py file
Second, serialization module
Sequence: list, tuple, string, bytes
Serialization: The process of converting a data type to a string, bytes type is serialization
Scenarios for serializing data types:
① storing a data type in a file
② when a data type is transmitted over the network
Eval and Exec: User input, file read-in, network incoming can not be used, there is a risk, extremely insecure.
Import JSON # importing JSON module
In JSON format, the strings you want are double quotes.
Json.dumps (obj) serialization process, converting to a string
ImportJson#Importing JSON modulesDIC = {'Province':'Guangdong province',' City':'Shenzhen'}s= Json.dumps (DIC)#the process of serializationPrint(S,type (s))#{"Province": "\u5e7f\u4e1c\u7701", "City": "\u6df1\u5733\u5e02"} <class ' str ' >
Json.loads (str) deserialization process, converted to the original type
ImportJson#Importing JSON modulesDIC = {'Province':'Guangdong province',' City':'Shenzhen'}s= Json.dumps (DIC)#the process of serializationDic2 = Json.loads (s)#the process of deserializationPrint(Dic2,type (dic2))#{' Province ': ' Guangdong province ', ' City ': ' Shenzhen '} <class ' Dict ' >
The advantages of JSON:
① all languages are universal.
The disadvantages of JSON:
① only supports very few data types
② constraints on data types are harsh
The key of the ③ dictionary must be a string
④ only supports data types: numbers, strings, lists, dictionaries
Python module, serialization module