I am wondering if it makes sense in Python to use a class containing a list as if it is an in-memory database.
class MyData(object):
def __init__(self):
self._data = ['apple', 'orange', 'banana']
@property
def data(self):
return self._data
@classmethod
def append(self, item):
self._data.append(item)
Here's the scenario:
A first python script a.py
will import this class MyData
and use the data in its list.
A second python script b.py
continuously poll an online API in an infinite loop, imports this same class and appends more items to the list.
When a.py
runs another time, it should be able to read the newly added items in the list.
Question: Is this a good idea, or are we better off using a real database like MySQL/redis?
Update: The data does not need to be persisted to disk