Search code examples
pythonfile-iocsvmultidimensional-arrayfileparsing

Simple data storing in 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.

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:

  • the array.toFile() method but couldn't figure out how to get it to work with nested arrays of strings, it seemed geared towards integer data.
  • Lists and sets do not have a toFile method built in, so I would have had to parse and encode it manually.
  • CSV seemed like a good approach but this would also require manually parsing it, and did not allow me to simply append new lines at the end - so any new calls the the CSVWriter would overwrite the file existing data.

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.


Solution

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