私はちょうどPythonを勉強していて、本当にシンプルなPythonロボットを書くことに決めました。私は、コードが私に正しく見えるとして、これを引き起こしているかを確認することができません私のコードがコンパイルされない理由
File "C:\Python35\Scripts\RedditBot\Reddit.py", line 28 except attributeerror: ^SyntaxError: invalid syntax
:私は次のエラーを取得していますコンパイルの
。
import praw
USERAGENT = "BOT Name"
USERNAME = "Username"
PASSWORD = "Password"
SUBREDDIT = "Subreddit"
MAXPOSTS = 100
SETPHRASES = ["Phrase", "PhraseOne"]
SETRESPONSE = "This is the response."
print('Logging in to Reddit')
r = praw.Reddit(USERAGENT)
r.login (USERNAME, PASSWORD)
def replybot():
print('Fetching Subreddit ' + SUBREDDIT)
subreddit = r.get_subreddit(SUBREDDIT)
print('Fetching comments')
comments = subreddit.get_comments(limit=MAXPOSTS)
for comment in comments:
try:
cauthor = comment.author.name
cbody = comment.body.lower()
if any(key.lower() in cbody for key in SETPHRASES):
print("Replying to " + cauthor)
comment.reply(SETRESPONSE)
except attributeerror:
pass
replybot()
さんを除いてインデントが – Lafexlos
はまたのように見えるが間違っている 'attributeerror'があるべき' AttributeError'は別の問題を避けるために。 – sytech
そしてPythonのインストールフォルダにあなた自身のスクリプトを入れたようです。それをしないでください。 – Matthias