Reputation: 9
i am using LRUCache from cachetools library, but when i am trying to append i am getting the error 'dict' object has no attribute 'append' though i understand what is the error, i cant seem to figure out any way to get around it, can someone help? here is a little code.
GivenQuestionsCache=LRUCache(maxsize=100,missing=getGivenQuestions)
now GivenQuestionsCache[1] gives
{1: [[211736, None], [211736, 'a'], [207113, 'a'], [219556, None], [207095, None], [89027, None], [89027, None]]}
and i am trying to do
GivenQuestionsCache[1].append([10,None])
then it throws that error. is there any other way to achieve this? i want my cache to become
{1: [[211736, None], [211736, 'a'], [207113, 'a'], [219556, None], [207095, None], [89027, None], [89027, None],[10,None]]}
Upvotes: 0
Views: 1086
Reputation: 948
I tested your code and it works:
from cachetools import LRUCache
GivenQuestionsCache=LRUCache(maxsize=100,missing=lambda _: dict())
GivenQuestionsCache[1] = [[211736, None], [211736, 'a'], [207113, 'a'], [219556, None], [207095, None], [89027, None], [89027, None]]
GivenQuestionsCache[1].append([10,None])
print GivenQuestionsCache[1]
returns
[[211736, None],
[211736, 'a'],
[207113, 'a'],
[219556, None],
[207095, None],
[89027, None],
[89027, None],
[10, None]]
But
GivenQuestionsCache[2].append([10,None])
will return
AttributeError: 'dict' object has no attribute 'append'
So you need to check all your code that potentially can modify GivenQuestionsCache.
Upvotes: 1