Polls¶
-
class
praw.models.reddit.poll.PollData(reddit: 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
This table describes attributes that typically belong to objects of this class. Since attributes are dynamically provided (see Determine Available Attributes of an Object), there is not a guarantee that these attributes will always be present, nor is this list necessarily complete.
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: Reddit, _data: Optional[Dict[str, Any]])¶ Initialize a PRAWModel instance.
- Parameters
reddit – An instance of
Reddit.
-
option(option_id: str) → praw.models.reddit.poll.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: Reddit) → Any¶ Return an instance of
clsfromdata.- Parameters
data – The structured data.
reddit – An instance of
Reddit.
-
user_selection¶ Get the user’s selection in this poll, if any.
- Returns
The user’s selection as a
PollOption, orNoneif there is no choice.
-
-
class
praw.models.reddit.poll.PollOption(reddit: Reddit, _data: Optional[Dict[str, Any]])¶ Class to represent one option of a poll.
If
submissionis a pollSubmission, access the poll’s options like so:poll_data = submission.poll_data # By index -- print the first option print(poll_data.options[0]) # By ID -- print the option with ID "576797" print(poll_data.option("576797"))
Typical Attributes
This table describes attributes that typically belong to objects of this class. Since attributes are dynamically provided (see Determine Available Attributes of an Object), there is not a guarantee that these attributes will always be present, nor is this list necessarily complete.
Attribute
Description
idID of the poll option.
textThe text of the poll option.
vote_countThe number of votes the poll option has received.
Note
This list of attributes is not complete. PRAW dynamically provides the attributes that Reddit returns via the API. Because those attributes are subject to change on Reddit’s end, PRAW makes no effort to document them, other than to instruct you on how to discover what is available. See Determine Available Attributes of an Object for detailed information.