Polls¶
- class praw.models.reddit.poll.PollData(reddit: praw.Reddit, _data: Optional[Dict[str, Any]])¶
Class to represent poll data on a poll submission.
If
submission
is 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
options
A list of
PollOption
of the poll.total_vote_count
The total number of votes cast in the poll.
user_selection
The poll option selected by the authenticated user (possibly
None
).voting_end_timestamp
Time the poll voting closes, represented in Unix Time.
- __init__(reddit: praw.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
KeyError
if no option exists with the specified ID.
- classmethod parse(data: Dict[str, Any], reddit: praw.Reddit) Any ¶
Return an instance of
cls
fromdata
.- Parameters
data – The structured data.
reddit – An instance of
Reddit
.
- user_selection() Optional[praw.models.reddit.poll.PollOption] ¶
Get the user’s selection in this poll, if any.
- Returns
The user’s selection as a
PollOption
, orNone
if there is no choice.
- class praw.models.reddit.poll.PollOption(reddit: praw.Reddit, _data: Optional[Dict[str, Any]])¶
Class to represent one option of a poll.
If
submission
is 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
id
ID of the poll option.
text
The text of the poll option.
vote_count
The number of votes the poll option has received.