使用Python进行基本数据存储 [英] Basic data storage with Python

查看:103
本文介绍了使用Python进行基本数据存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要存储客户和他们购买的汽车的基本数据以及这些汽车的付款时间表。这些数据来自用Python编写的GUI。我没有足够的经验来使用sql等数据库系统,因此我想将数据以纯文本格式存储在文件中。而且不必在线。

I need to store basic data of customer's and cars that they bought and payment schedule of these cars. These data come from GUI, written in Python. I don't have enough experience to use a database system like sql, so I want to store my data in a file as plain text. And it doesn't have to be online.

为了能够搜索和过滤它们,首先我将数据(列表列表)转换为字符串,然后在需要将数据重新转换为常规Python时使用列表语法。我知道这是一种蛮力的方式,但是这样做安全吗?或者您可以建议我采用另一种方式吗?

To be able to search and filter them, first I convert my data (lists of lists) to the string then when I need the data re-convert to the regular Python list syntax. I know it is a very brute-force way, but is it safe to do like that or can you advice me to another way?

推荐答案

以文本格式(或使用pickle或其他方式)保存数据库永远都不安全。保存数据时出现问题可能会导致损坏。更不用说数据被盗的风险了。

It is never safe to save your database in a text format (or using pickle or whatever). There is a risk that problems while saving the data may cause corruption. Not to mention risks with your data being stolen.

随着数据集的增长,性能可能会受到影响。

As your dataset grows there may be a performance hit.

看一下sqlite(或sqlite3),它比mysql小且易于管理。除非您有一个非常小的数据集适合文本文件。

have a look at sqlite (or sqlite3) which is small and easier to manage than mysql. Unless you have a very small dataset that will fit in a text file.

P / S:btw,在python中使用berkeley db很简单,而且您没有要了解所有数据库知识,只需导入bsddb

P/S: btw, using berkeley db in python is simple, and you don't have to learn all the DB things, just import bsddb

这篇关于使用Python进行基本数据存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆