Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. class AudioFile:
  2. # Note self.ext, self.filename, this is how polymorphism works.
  3. def __init__(self, filename):
  4. if not filename.endswith(self.ext):
  5. raise Exception("Invalid file format")
  6. self.filename = filename
  7.  
  8. def play(self):
  9. print("playing {} as {}".format(self.filename,self.ext))
  10.  
  11.  
  12. class MP3File(AudioFile):
  13. ext = 'mp3'
  14.  
  15. class WavFile(AudioFile):
  16. ext = 'wav'
  17.  
  18. class OggFile(AudioFile):
  19. ext = 'ogg'
  20.  
  21. audio_file = MP3File('hello.mp3')
  22. audio_file.play()
  23. """
  24. playing hello.mp3 as mp3
  25. """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement