Creating a grandchild class
In this exercise you will be using inheritance to create a Tweets class from your SocialMedia class. This new grandchild class of Tweets 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
classstatement so thatTweetsinherits fromSocialMedia.SocialMediahas 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_lineswith the correct parameter name.filter_lineshas already been loaded in your environment. returnretweet_textfrom_process_retweetsas 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)