JSON (JavaScript Object Notation) data read in python

Use json.dump () to store a list of numbers:

import json

numbers = [2, 3, 5, 7, 11, 13]

filename = 'numbers1.json'
with open(filename, 'w') as file_object:
    json.dump(numbers, file_object)

We import the module first json, and then create a list of numbers. We specify that you want to store the list of numbers to which
the name of the file. Typically use the file extension .jsonto indicate the data file storage for the JSONformat. Next, we
open the file in write mode, so that jsoncan write data therein. We use the function json.dump()
to a list of numbers stored in the file numbers1.jsonin.
Use json.load () will read this list into memory:

import json

filename = 'numbers1.json'
with open(filename) as file_object:
    numbers = json.load(file_object)
    
print(numbers)
Published 145 original articles · won praise 6 · views 8054

Guess you like

Origin blog.csdn.net/sinat_23971513/article/details/105054831