MMBazel/Springboard-DataScienceTrack-Student

When using ParentClass's __init__ method, why pass in parents' argument too ?

johnhhu2020 opened this issue · 1 comments

Hello, I saw your sharing, it's great finding some useful studying material with so many code samples. Thank you.

Here I was confused on DataCamp Data Engineering with Python course, can you please help me clarify it? The inheritance question ######

jhu@debian:~/datacmap_data_engineering$ cat text_analyzer/social_media.py 
from text_analyzer import Document
from collections import Counter


# Define a SocialMedia class that is a child of the `Document class`
class SocialMedia(Document):
    def __init__(self, text):
        Document.__init__(self, text)          ######## ???? Here, why we pass 'text' too???
        self.hashtag_counts = self._count_hashtags()
        self.mention_counts = self._count_mentions()

    def _count_hashtags(self):
        # Filter attribute so only words starting with '#' remain
        return SocialMedia.filter_word_counts(self.word_counts, first_char='#')  

    def _count_mentions(self):
        # Filter attribute so only words starting with '@' remain
        return SocialMedia.filter_word_counts(self.word_counts, first_char='@')

Problem solved