In [32]:
class Post:
    def __init__(self, author, text):
        
        print("Setting post data:", author, text)
        self.author = author
        self.text = text
        self.post_time = "Now"
        self.reactions = []
        self.comments = []
        
    def create(self):
        print("Post.create() called")
        
    def react(self):
        print("Post.react() called")
        
    def comment(self):
        print("Post.comment() called")
        
    def edit(self):
        print("Post.edit() called")
        
    def delete(self):
        print("Post.delete() called")
In [55]:
class CheckIn(Post):
    
    def __init__(self, author, text, location):
        super().__init__(author, text)
        
        self.location = location
        
    def create(self):
#         super().create()
        print("CheckIn.create() called")
        
    def update_location(self):
        print("CheckIn.update_location() called")
        
    def set_location_name(self):
        print("CheckIn.set_location_name() called")
        
In [56]:
x = CheckIn("Cody", "Test post", "UMD")
x.comment()
Setting post data: Cody Test post
Post.comment() called
In [57]:
x.create()
CheckIn.create() called
In [37]:
x.set_location_name()
CheckIn.set_location_name() called
In [50]:
class Picture(Post):
    
    def __init__(self, author, text, media):
        super().__init__(author, text)
        
        self.media = media
        
    def create(self):
        print("Picture.create() called")
        
In [51]:
y = Picture("Cody", "My picture description", "<waving>")
y.create()
Setting post data: Cody My picture description
Picture.create() called
In [53]:
y.text
Out[53]:
'My picture description'
In [40]:
issubclass(CheckIn, Post)
Out[40]:
True
In [41]:
isinstance(CheckIn("Cody", "Text", "UMD"), CheckIn)
Setting post data: Cody Text
Out[41]:
True
In [42]:
isinstance(CheckIn("Cody", "Text", "UMD"), Post)
Setting post data: Cody Text
Out[42]:
True
In [28]:
# What happens without the call to super() in the initializer?
In [ ]:

In [30]:
class Pet:
    def speak(self):
        print(self.sound)
        
    def identify(self):
        print("I am a pet", self.kind)
        
    def __str__(self):
        return "I am a pet %s" % self.kind
    
class Fish(Pet):
    kind = "fish"
    sound = "bloop"
    
class Dog(Pet):
    kind = "dog"
    sound = "whoof!"
In [31]:
f = Fish()

f.speak()
bloop
In [ ]: