Python module, serialization module

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.