import praw import time class getPms(): r = praw.Reddit(user_agent="Test Bot By /u/TheC4T") r.login(username='*************', password='***************') cache = [] inboxMessage = [] file = 'cache.txt' def __init__(self): cache = self.cacheRead(self, self.file) self.bot_run(self) self.cacheSave(self, self.file) time.sleep(5) return self.inboxMessage def getPms(self): def bot_run(): inbox = self.r.get_inbox(limit=25) print(self.cache) # print(r.get_friends())#this works for message in inbox: if message.id not in self.cache: # print(message.id) print(message.body) # print(message.subject) self.cache.append(message.id) self.inboxMessage.append(message.body) # else: # print("no messages") def cacheSave(self, file): with open(file, 'w') as f: for s in self.cache: f.write(s + '\n') def cacheRead(self, file): with open(file, 'r') as f: cache1 = [line.rstrip('\n') for line in f] return cache1 # while True: #threading is needed in order to run this as a loop. Probably gonna do this in the main method though # def getInbox(self): # return self.inboxMessage The exception is:
cache = self.cacheRead(self, self.file) AttributeError: 'getPms' object has no attribute 'cacheRead' I am new to working with classes in python and need help with what I am doing wrong with this if you need any more information I can add some. It worked when it was all functions but now that I attempted to switch it to a class it has stopped working.