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")
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")
x = CheckIn("Cody", "Test post", "UMD")
x.comment()
x.create()
x.set_location_name()
class Picture(Post):
def __init__(self, author, text, media):
super().__init__(author, text)
self.media = media
def create(self):
print("Picture.create() called")
y = Picture("Cody", "My picture description", "<waving>")
y.create()
y.text
issubclass(CheckIn, Post)
isinstance(CheckIn("Cody", "Text", "UMD"), CheckIn)
isinstance(CheckIn("Cody", "Text", "UMD"), Post)
# What happens without the call to super() in the initializer?
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!"
f = Fish()
f.speak()