PollData#
- class praw.models.reddit.poll.PollData(reddit: praw.Reddit, _data: Optional[Dict[str, Any]])#
Class to represent poll data on a poll submission.
If
submissionis a pollSubmission, access the poll data like so:poll_data = submission.poll_data print(f"There are {poll_data.total_vote_count} votes total.") print("The options are:") for option in poll_data.options: print(f"{option} ({option.vote_count} votes)") print(f"I voted for {poll_data.user_selection}.")
Typical Attributes
Note
This table describes attributes that typically belong to objects of this class. PRAW dynamically provides the attributes that Reddit returns via the API. Since those attributes are subject to change on Reddit’s end, PRAW makes no effort to document any new/removed/changed attributes, other than to instruct you on how to discover what is available. As a result, this table of attributes may not be complete. See Determine Available Attributes of an Object for detailed information.
If you would like to add an attribute to this table, feel free to open a pull request.
Attribute
Description
optionsA list of
PollOptionof the poll.total_vote_countThe total number of votes cast in the poll.
user_selectionThe poll option selected by the authenticated user (possibly
None).voting_end_timestampTime the poll voting closes, represented in Unix Time.
- __init__(reddit: praw.Reddit, _data: Optional[Dict[str, Any]])#
Initialize a
PRAWBaseinstance.- Parameters:
reddit – An instance of
Reddit.
- option(option_id: str) PollOption#
Get the option with the specified ID.
- Parameters:
option_id – The ID of a poll option, as a
str.- Returns:
The specified
PollOption.- Raises:
KeyErrorif no option exists with the specified ID.
- classmethod parse(data: Dict[str, Any], reddit: praw.Reddit) Any#
Return an instance of
clsfromdata.- Parameters:
data – The structured data.
reddit – An instance of
Reddit.
- user_selection() Optional[PollOption]#
Get the user’s selection in this poll, if any.
- Returns:
The user’s selection as a
PollOption, orNoneif there is no choice.