首页 > 解决方案 > Check if user exists with PRAW

问题描述

Is it possible to check if a specified user exists using PRAW, and if so what is the proper way to do so? I couldn't find any builtin functions that do this, so your help would be appreciated.

标签: pythonsearchredditpraw

解决方案


Arnav 的答案仅适用于旧版本的 PRAW(2016 年之前)。如果你开始一个新项目,你应该使用最新版本的 PRAW。在该版本中,这是有效的代码:

import praw
from prawcore.exceptions import NotFound

reddit = praw.Reddit(  # authentication goes here
)

def user_exists(name):
    try:
        reddit.redditor(name).id
    except NotFound:
        return False
    return True

推荐阅读