在 Python 中创建用户配置文件
我正在用 pygame 制作一个小型 python 游戏。我希望能够拥有多个具有不同统计数据、升级等的配置文件。我最大的问题是持久存储这些信息。我已经考虑过 MySql,但我不知道如何连接到它,我更喜欢某种无需数据库即可分发它的方法。有什么建议吗?非常感谢。
I'm making a small python game with pygame. I'd like to be able to have multiple profiles with different stats, upgrades, etc. My biggest problem is storing this information persistently. I've already thought about MySql but I don't know how I could connect to it and I would prefer some way to be able to distribute it without requiring a database. Any suggestions? Many thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 python 附带的 sqlite3 模块,或者您可以使用 shelve 模块
您可以使用 shelve 模块作为对象数据库,直接保存用户类。
sqlite3 模块允许您将关系数据库存储在文件中。例如,Firefox 使用它。
You can use the sqlite3 module which comes with python or you could use the shelve module
You can use the shelve module as an object database and just save the user classes directly.
The sqlite3 module will let you store a relational database in a file. It's used by firefox for example.
sqllite3
可能是最简单的方法。它是轻量级的,不需要用户安装。不过,要访问它,请考虑使用 ORM(对象关系映射器)来简化事情。 SQL Alchemy 和 Storm都是很好的工具。ORM 处理编写 SQL 代码等的细节。如果您想在数据库之间跳转,通常只需更改一行代码即可。
sqllite3
will probably be the easiest way forward. It's lightweight and doesn't need to be installed by users. To access it though, consider using an ORM (Object Relational Mapper) to simplify things. SQL Alchemy and Storm are both good tools.An ORM deals with the nitty-gritty of writing SQL code and so forth. If you want to hop between databases, it's often just a matter of changing a single line of code.