print("playing {as wavformat(self filename)class oggfile(audiofile)ext "oggdef play(self)print("playing {as oggformat(self filename)all audio files check to ensure that valid extension was given upon initialization but did you notice how the __init__ method in the parent class is able to access the ext class variable from different subclassesthat' polymorphism at work if the filename doesn' end with the correct nameit raises an exception (exceptions will be covered in detail in the next the fact that audiofile doesn' actually store reference to the ext variable doesn' stop it from being able to access it on the subclass in additioneach subclass of audiofile implements play(in different way (this example doesn' actually play the musicaudio compression algorithms really deserve separate book!this is also polymorphism in action the media player can use the exact same code to play fileno matter what type it isit doesn' care what subclass of audiofile it is looking at the details of decompressing the audio file are encapsulated if we test this exampleit works as we would hopeogg oggfile("myfile ogg"ogg play(playing myfile ogg as ogg mp mp file("myfile mp "mp play(playing myfile mp as mp not_an_mp mp file("myfile ogg"traceback (most recent call last)file ""line in file "polymorphic_audio py"line in __init__ raise exception("invalid file format"exceptioninvalid file format see how audiofile __init__ is able to check the file type without actually knowing what subclass it is referring to