我不知道为什么它认为这个函数变量是list
。该问题发生在编译时该代码的第41行(在addPoint()
函数中)。我尝试过使用user
全局变量来代替它,但它仍然不起作用。我觉得有一些简单的东西我错过了,但无法确定。在
import praw
import time
import re
import pickle
from classes import User
USERAGENT = 'web:CredibilityBot:v0.1 (by /u/ThePeskyWabbit)'
FOOTER = "^^I ^^am ^^a ^^bot! ^^I ^^am ^^currently ^^in ^^test ^^phase. ^^Read ^^about ^^me ^^[here](https://pastebin.com/jb4kBTcS)."
PATH = "C:\\Users\\JoshLaptop\\PycharmProjects\\practice\\commented.txt"
user = User.User("placeholder")
commentFile = open(PATH, 'rb')
commentList = commentFile.read().splitlines()
commentFile.close()
pkl = open("userpkl.pkl", 'rb')
pklList = []
try:
while(True):
pklList.append(pickle.load(pkl))
except EOFError:
pass
pkl.close()
nameList = []
try:
for data in pklList:
user = data
nameList.append(str(user.getName()))
except:
pass
print(pklList)
print(nameList)
def addPoint(userInstance, comment):
userInstance.addScore()
userInstance.addComment(comment)
message = "Bullshit noted! " + userInstance.getName() + " now has a Bullshit rating of \n\n" + userInstance.getScore() + FOOTER
return message
编写该方法的类如下:
^{pr2}$我的错误输出是:
File "C:/Users/JoshLaptop/PycharmProjects/practice/TestBot.py", line 63, in <module>
actions = {"!bullshit": addPoint(user, commentLink), "!bullshitrating": getRating(user), "!bullshitdetail":getCommentList(user)}
File "C:/Users/JoshLaptop/PycharmProjects/practice/TestBot.py", line 41, in addPoint
userInstance.addScore()
AttributeError: 'list' object has no attribute 'addScore'
发现了问题。问题在于此尝试:
通过删除
user = data
并将user.getName()
改写为data.getName()
,问题得到了解决。很奇怪相关问题 更多 >
编程相关推荐