Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How python json saves data

Shulou Source: shulou.com Published: 2022-05-31 10:38:14 09月11日 Update

This article editor for you a detailed introduction of "python json how to save data", the content is detailed, the steps are clear, the details are handled properly, I hope this "python json how to save data" article can help you solve your doubts, following the editor's ideas slowly deepen, let's learn new knowledge.

Description

1. Python uses json.dump () and json.load () to store and read json files.

2. Be careful to import the json module before using it.

Example

Import json userInfo = {'username':' jack', 'age': 18} with open (' test.txt',') as obj: json.dump (userInfo, obj) with open ('test.txt') as obj: content = json.load (obj) print (content)

Use json.dump () to store the data in test.txt, and then use json.load () to take the data out of the file and print it.

After reading this, the article "how to preserve data in python json" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about related articles, welcome to follow the industry information channel.

Tags: Data articles content documents proper leading examples ideas new knowledge more modules steps knowledge knowledge points articles details industry information information channels follow Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Xiaomi Shulou Information MySQL macOS