I've been trying to add a functionality to a class, without changing its behavior. But it gives an AttributeError. How do I code this? (PS: You don't need to know praw
for this)
In the following: the Comment
object is returned from Reddit
object.
from praw import Reddit
from praw.models import Comment
class Comment(Comment):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
print("this is my Comment")
def is_awesome(self):
return True
class Reddit(Reddit):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
print("this is my Reddit")
# this is my Reddit object
reddit = Reddit("some args")
# this is a Comment object from praw
k = reddit.comment(id="hzfbs3e")
# this gives an `AttributeError`
k.is_awesome()
# for example there is also this
k.author # which returns a `Redditor` object