Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to persist data between executions in Python

I am working on a personal project in Python where I need some form of persistent data. The data would fit in 2-3 tables of 10-20 columns and 100-200 records each. I have a basic understanding of SQL, so a database seems to make some sense.

I am new to Python, so I am not familiar with the options for database interface from Python. I have also heard about pickling and am not sure if that would be a better solution for my project size. Can anyone recommend a good solution?

like image 726
astay13 Avatar asked May 28 '11 10:05

astay13


People also ask

How does Python store persistent data?

The standard library includes a variety of modules for persisting data. The most common pattern for storing data from Python objects for reuse is to serialize them with pickle and then either write them directly to a file or store them using one of the many key-value pair database formats available with the dbm API.

How can you store data in Python?

Using Python's built-in File object, it is possible to write string data to a disk file and read from it. Python's standard library, provides modules to store and retrieve serialized data in various data structures such as JSON and XML. Python's DB-API provides a standard way of interacting with relational databases.

How do you persist data?

Enabling data persistence on data variablesSelect a data variable from your list. If the list is empty, create a data variable that you want to persist. For the Persist data to value, set to User or Application. Tip: Only persist data for fields that are necessary for your business application.

What is persistent storage of objects in Python?

The Persistent Storage module minimizes database activity by caching retrieved objects and by saving objects only after their attributes change. To relieve code writing tedium and reduce errors, a code generator takes a brief object description and creates a Python module for a persistent version of that object.


1 Answers

Or, if you just want to persist data between executions - for such a small data set you could have a look at the pickle module for persistency, and just load the data into memory during execution.

It's a simple solution - but for a personal project it might be enough.

like image 106
Abizern Avatar answered Sep 18 '22 18:09

Abizern