Python Data Persistence 简明教程
Python Data Persistence - Introduction
Overview of Python - Data Persistence
在使用任何软件应用程序的过程中,用户都会提供一些要处理的数据。数据可能是使用标准输入设备(键盘)或其他设备(如磁盘文件、扫描仪、照相机、网线、WiFi 连接等)输入的。
During the course of using any software application, user provides some data to be processed. The data may be input, using a standard input device (keyboard) or other devices such as disk file, scanner, camera, network cable, WiFi connection, etc.
接收到的数据存储在计算机的主存储器(RAM)中,采用各种数据结构(如变量和对象)的形式,直到应用程序正在运行。此后,来自 RAM 的内存内容将被擦除。
Data so received, is stored in computer’s main memory (RAM) in the form of various data structures such as, variables and objects until the application is running. Thereafter, memory contents from RAM are erased.
然而,通常情况下,人们希望变量和/或对象的值以某种方式存储,以便可以在需要时检索该值,而不是再次输入相同的数据。
However, more often than not, it is desired that the values of variables and/or objects be stored in such a manner, that it can be retrieved whenever required, instead of again inputting the same data.
“持久性”一词意为“在其成因被移除之后仍在持续存在的效应”。数据持久性一词表示它在应用程序结束后仍然存在。因此,存储在非易失性存储介质(如磁盘文件)中的数据是一种持久性数据存储。
The word ‘persistence’ means "the continuance of an effect after its cause is removed". The term data persistence means it continues to exist even after the application has ended. Thus, data stored in a non-volatile storage medium such as, a disk file is a persistent data storage.
在本教程中,我们将探讨各种内置和第三方 Python 模块,以将数据存储和检索到/从各种格式,如文本文件、CSV、JSON 和 XML 文件以及关系数据库和非关系数据库。
In this tutorial, we will explore various built-in and third party Python modules to store and retrieve data to/from various formats such as text file, CSV, JSON and XML files as well as relational and non-relational databases.
使用 Python 的内置文件对象,可以将字符串数据写入磁盘文件并从中读取数据。Python 的标准库提供了模块,以存储和检索序列化数据,这些数据位于各种数据结构中,如 JSON 和 XML。
Using Python’s built-in File object, it is possible to write string data to a disk file and read from it. Python’s standard library, provides modules to store and retrieve serialized data in various data structures such as JSON and XML.
Python 的 DB-API 提供了一种与关系数据库交互的标准方法。其他第三方 Python 软件包提供了与 NOSQL 数据库(如 MongoDB 和 Cassandra)的接口功能。
Python’s DB-API provides a standard way of interacting with relational databases. Other third party Python packages, present interfacing functionality with NOSQL databases such as MongoDB and Cassandra.
本教程还介绍 ZODB 数据库,这是 Python 对象的持久性 API。Microsoft Excel 格式是一种非常流行的数据文件格式。在本教程中,我们将学习如何通过 Python 处理 .xlsx 文件。
This tutorial also introduces, ZODB database which is a persistence API for Python objects. Microsoft Excel format is a very popular data file format. In this tutorial, we will learn how to handle .xlsx file through Python.