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.
Diese Übung ist Teil des Kurses
Software Engineering Principles in Python
Anleitung zur Übung
- 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
.
Interaktive Übung
Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.
# 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)