Serialization of Python3--json

Source: Internet
Author: User
# Auther:aaron Fan

# Deposit data into a file

# JSON-formatted data can be almost universally spoken in any programming language, but simply a simple format conversion
# For example: dictionaries, lists, tuples, strings, and so on, like functions, classes can not be converted.
# python has a module that supports all format conversions: pickle, but the pickle format cannot be used in any other language, only in Python!
# Pickle's use is exactly the same as JSON, just use it to change the JSON to pickle (there is a slight difference between the function and the class when you need to check it out).

# 2.7 The inside dump and load can be saved multiple times and taken multiple times. But 3.x uses JSON to keep in mind one principle: data storage is always dump once, then load once.
# If you really want to save several states, dump several files, and then go to load the files.

Import JSON

info = {
' Name ': ' Aaron ',
' Age ': 21
}

With open (' Test.txt ', ' W ', encoding= ' utf-8 ') as F:
F.write (Json.dumps (info))
# Shopping cart in that program, saving the balance is useful for another way of writing, the function is exactly the same as the wording of the different

Serialization of Python3--json

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.