在Python中简单的数据存储 [英] Simple data storing in Python

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

问题描述

我正在寻找一个简单的解决方案,使用Python将数据存储为一个平面文件,这样每行都是一个字符串表示的数组,可以很容易地解析。

I'm looking for a simple solution using Python to store data as a flat file, such that each line is a string representation of an array that can be easily parsed.

我相信python有图书馆做这样的任务很容易,但到目前为止所有的方法,我发现看起来像是草草,让它工作,我相信有一个更好的方法。到目前为止我试过:

I'm sure python has library for doing such a task easily but so far all the approaches I have found seemed like it would have been sloppy to get it to work and I'm sure there is a better approach. So far I've tried:


  • array.toFile()方法,但是无法弄清楚如何使它与嵌套

  • 列表和集合没有内置的toFile方法,因此我不得不手动解析和编码它。

  • CSV似乎是一个很好的方法,但这也需要手动解析它,并且不允许我在结尾添加新行 - 所以任何新的调用CSVWriter会覆盖

我真的试图避免使用数据库(也许SQLite,但似乎有点过分),因为我试图开发这个,除了Python之外没有软件先决条件。

I'm really trying to avoid using databases (maybe SQLite but it seems a bit overkill) because I'm trying to develop this to have no software prerequisites besides Python.

推荐答案

如果没有,搁置非常容易使用。

Must the file be human readable? If not, shelve is really easy to use.

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

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