1) Simple text file using open()
pros: Anybody can do it
cons: Not Pythonic
2) Write data as a Python script, import it to read
pros: Pythonic, flexible
cons: .pyc file may cause problem on some occasion. The user needs to know at least basic Python script.
3) XML
pros: Any programming language has XML parsers. Python has one in the std modules.
cons: XML is Ugly.
4) YAML
pros: Much more human eyes friendly than XML.
cons: Not yet well known, not in the std modules in Python, maybe 2) is enough?
5) pickle
pros: Good for storing Python generated data, std module.
cons: None
6) shelf
pros: Good for storing key-value data, std module.
cons: Somehow it doesn't seem useful to me.
7) sqlite3
pros: Can be used as a simple database, std module (Python version >=2.5).
cons: Need to know SQL (A friend of mine recommends sqlalchemy but I haven't used it yet)
8) zodb
pros: Support redo/undo, Object database (reconstruct references).
cons: Not in the std modules, Not good for very frequent write accesses (slow).
9) JSON
pros: Same as YAML.
cons: Same as YAML.
What else?
Wednesday, February 18, 2009
Various ways to have data in a file
Subscribe to:
Post Comments (Atom)
4 comments:
I vote 2). Write data in python script seems a good idea.
Hi syoyo san konchi ha-
It's my favourite too. It's especially good for user preference files. One bad thing with this which I didn't mention is that it can be a potential security risk.
Hmm, but for the use of CG(e.g. 3D scene file), considering security problem might be less important.
Another candidate is JSON.
That's one good thing about CG programming ;)
Post a Comment