How can you create a class attribute that will always contain the same list? It should always reference the same list although the contents of the list can be changed.
The obvious solution is to use property.
class Table(list):
def filter(kwargs):
"""Filter code goes here."""
class db:
_table = Table([1, 2])
table = property(lambda self: self._table)
db.table.append(3)
I would have assumed that db.table should return a list and that you should be able to append to this list. But no, this code throws an exception:
AttributeError: 'property' object has no attribute 'append'
How do you create a attribute that always refers to the same list?
ILLUSTRATION:
db.table = [x for x in db.table if x > 2]
db.filter(3) # This filter method got lost when reassigning the table in the previous line.