Oldboy 23th Day. I Love Python. Module initialization, and serialization module

Source: Internet
Author: User
Tags serialization

First, today's main content:
Module: A py file is a module
Divided into three categories: 1, built-in modules: Login module, TIME module, SYS module, OS module, etc. are built-in modules
2, Expansion module: Third-party modules that need to be downloaded
3, Custom module: Write your own module.
1, serialization module: JSON, Pickle, shelve (Learn)
Serialization: Creating a sequence (a sequence of string types) a data type---> serialized string
Deserialization process: serialized string---> The type of data she corresponds to.

JSON: Applies to different languages, but the supported data types are relatively rare and only: strings, numbers, lists, dictionaries. There are 4 ways: for network transmission: dumps () <--> loads () for access to files: Dump () <--> load ()
1, the data is sent to someone via the network:
Json.dumps (the content that needs to be converted to JSON.) The resulting string type, but this string, not the string, is The serialized string, which can be sent directly on the network, can also be understood by other languages, and the difference between the string and the string is: This string is a double quote, and the string is a single quote
Json.loads (the data that was Json.dumps): the deserialization process.
2, write the file.
Json.dump (obj, fq) obj = object, Fq = File handle. The serialized string is written to the file
Json.load (FQ) FQ = file handle, read, deserialized String,
PS: Writes multiple serialized strings to the file and then deserializes, an error occurs. If you really want to write more than one, you need to use dumps and loads, if it is a dictionary, key must be a string

Pickle: The serialization module is used only between Python and can support all Python data types. There are also 4 methods (two pairs) for network transmission: Dumps () <-->loads () for file operation: dump<---load ()
1, Network transmission
Pickle.dumps () will be converted into bytes type and cannot be decode.
Pickle.loads () converts the bytes into a data type that can be viewed and used.
2, file operation
Pickle.dump ()
Pickle.load ()
PS: These two are better than JSON, he can read a lot of different lists, but

Shelve: Only for Python, more like a gadget. FILE-related
2, abstract algorithm: Hashlib

Oldboy 23th Day. I Love Python. Module initialization, and 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.