Creating a grandchild class
In this exercise you will be using inheritance to create a Tweet
class from your SocialMedia
class. This new grandchild class of Document
will be able to tackle Twitter specific details such as retweets.
This exercise is part of the course
Software Engineering Principles in Python
Exercise instructions
- Complete the
class
statement so thatTweets
inherits fromSocialMedia
.SocialMedia
has already been loaded in your environment. - Use
super()
to call the__init__
method of the parent class. - Define
retweet_text
. Usehelp()
to complete the call tofilter_lines
with the correct parameter name.filter_lines
has already been loaded in your environment. return
retweet_text
from_process_retweets
as an instance ofSocialMedia
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Define a Tweet class that inherits from SocialMedia
class Tweets(____):
def __init__(self, text):
# Call parent's __init__ with super()
____
# Define retweets attribute with non-public method
self.retweets = self._process_retweets()
def _process_retweets(self):
# Filter tweet text to only include retweets
retweet_text = filter_lines(self.text, ____='RT')
# Return retweet_text as a SocialMedia object
return ____(retweet_text)