Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 忽略区分大小写的关键字集_Python_Api_Reddit_Praw - Fatal编程技术网

Python 忽略区分大小写的关键字集

Python 忽略区分大小写的关键字集,python,api,reddit,praw,Python,Api,Reddit,Praw,我试图在使用PRAW搜索特定子Reddits上的关键字时忽略大小写敏感度 def run_bot(r, comments_replied_to): print "Obtaining 25 comments..." keywords = {"eyebleach", "eye bleach", "enough internet for today", "enough internet for the day"} for comment in r.subreddit('tes

我试图在使用PRAW搜索特定子Reddits上的关键字时忽略大小写敏感度

def run_bot(r, comments_replied_to):
    print "Obtaining 25 comments..."

    keywords = {"eyebleach", "eye bleach", "enough internet for today", "enough internet for the day"}
    for comment in r.subreddit('test').comments(limit=25):
        for keyword in keywords:
            if keyword.lower() in comment.body and comment.id not in comments_replied_to and comment.author != r.user.me():
                print "Keyword found in comment " + comment.id + "!"

                posts = r.subreddit('eyebleach').random()
                print("Generated random image post from /r/eyebleach: " + posts.url)

                comment_reply = "[**Need some eye bleach?**](%s)" % posts.url

                comment_reply += "\n\n/u/eyebleacher_bot was created by [@cjgetty](http://github.com/cjgetty).\n\nThis eye bleach has been randomly generated from [/r/eyebleach](http://reddit.com/r/eyebleach)."

                comment.reply(comment_reply)
                print "Replied to comment " + comment.id + "!"

                comments_replied_to.append(comment.id)

                with open ("comments_replied_to.txt", "a") as f:
                    f.write(comment.id + "\n")

        print "Sleeping for 10 seconds..."
        #Sleep for 10 seconds...
        time.sleep(10)
keywords
集合中,如何搜索任何大小写(小写、大写、混合)的相同关键字?

使用
str.lower()
方法,您可以不区分大小写地比较两个字符串。比如说

a = 'sTriNg LoWeR'
b = 'string lower'
c = 'STRING LOWER'

if(a.lower() == b.lower() == c.lower()):
    print('All equal!')
打印<代码>全部相等

if keyword.lower() in comment.body and comment.id not in comments_replied_to and comment.author != r.user.me():

您可以在if语句中添加一个.lower()comment.body

为什么不能只“lower()”注释body
if keyword.lower() in comment.body.lower() and comment.id not in comments_replied_to and comment.author != r.user.me():