I have been learning python for around a week and am trying to set up a basic LRU Cache.
I think I don't fully understand when to use the self command in OOP.
A simplified version of my code is here:
class LRUCache:
def __init__(self):
self.cache=[]
def add_to_cache(self, cache, item_to_add):
pass
my_cache = LRUCache()
while True:
what_to_add = input("What do you want to add?")
my_cache.add_to_cache(self.cache, what_to_add)
I get an error on the self.cache in the last line, "undefined name self"
I'm not quite sure why I get this- to my understanding my_cache is my object and it should be able to recognize self.cache, and uses that attribute within the add_to_cache function.
I tried searching around both here and on google, but was not able to specifically find what I did wrong.
I appreciate anyone's help or clarity on this situation. I am a beginner and still trying to learn. Thank you!