views:

47

answers:

2

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.

+2  A: 

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.

aaronasterling
+1 for referencing `shelf`
fmark
Perfect! A persistent dictionary is exactly what I need.
John
+1  A: 

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.

Tim McNamara
These look great for bigger programs and I'll definitely keep them in mind for later but I think for the small scale of my game, simply using the "shelve" module would be best.
John
I think so too. Good luck with the game!
Tim McNamara