Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class AudioFile:
- # Note self.ext, self.filename, this is how polymorphism works.
- def __init__(self, filename):
- if not filename.endswith(self.ext):
- raise Exception("Invalid file format")
- self.filename = filename
- def play(self):
- print("playing {} as {}".format(self.filename,self.ext))
- class MP3File(AudioFile):
- ext = 'mp3'
- class WavFile(AudioFile):
- ext = 'wav'
- class OggFile(AudioFile):
- ext = 'ogg'
- audio_file = MP3File('hello.mp3')
- audio_file.play()
- """
- playing hello.mp3 as mp3
- """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement