我正在尝试学习如何在Python中制作Reddit僵尸程序,但我收到以下错误消息......
C:\Users\Warbz\Desktop>python redditbot.py
Logging in...
Grabbing subreddit...
Grabbing comments...
Traceback (most recent call last):
File "redditbot.py", line 30, in <module>
run_bot()
File "redditbot.py", line 19, in run_bot
for comment in subredditComments:
TypeError: 'CommentHelper' object is not iterable
我的代码就是这个......
import praw
r = praw.Reddit(client_id="***",
client_secret="***",
username="***",
password="***",
user_agent = "/u/Fazy89")#Description of the script
print("Logging in...")
words_to_match = ['definately', 'defiantly', 'definantly', 'definatly', 'definitly']
cache = []#ID's of comments already replied to
def run_bot():
print("Grabbing subreddit...")
subreddit = r.subreddit("test")#Get SubReddit e.g /r/test
print("Grabbing comments...")
subredditComments = subreddit.comments
for comment in subredditComments:
comment_text = comment.body.lower()#Assign variable to lower case body of text
isMatch = any(string in comment_text for string in words_to_match)
if comment.id not in cache and isMatch:#^If comment has not been added to cache and is a match
print("Match found! Comment ID: " +comment.id)
comment.reply('I think you meant to say "Definitely".')
print("Reply successful!")
cache.append(comment.id)#Add comment ID to cache
print("Comments loop finished, going to sleep...")
while True:
run_bot()
time.sleep(10)
我已经尝试过查看PRAW api,但我不确定实际出现了什么问题,请帮忙吗?
答案 0 :(得分:1)
custom_test <- function(data, coeff, alt,
alternative = c("two.sided", "greater", "less"),
clevel = .95){
dof <- data$df.residual
top <- data$coefficients[coeff] - alt
bottom <- coef(summary(data))[coeff, "Std. Error"]
stat <- abs(top/bottom)
if ( alternative == "two.sided" ) {
return(2 * (1 - pt(stat, dof)))
} else if ( alternative == "greater" ) {
return(1 - pt(stat, dof))
} else if ( alternative == "less" ) {
return(1 - pt(stat, dof))
} else {
stop("Provide a valid alternative hypothesis.", call.=FALSE)
}
}
custom_test(fit9, 'hrsemp', 0, alternative="less")
hrsemp
7.858176e-05
custom_test(fit9, 'hrsemp', 0, alternative="two.sided")
hrsemp
0.0001571635
coef(summary(fit9))['hrsemp', 'Pr(>|t|)']
[1] 0.0001571635
提供了CommentHelper的一个实例,需要使用括号实例化它来调用它。
comments