trywebbrowser(filename**optionsgeneral scheme def playfile(filenamemimetable=mimetable**options)""play media file of any typeuses mimetypes to guess media type and map to platform-specific player tablesspawn web browser if text/htmlmedia type unknownor has no table ""contenttypeencoding mimetypes guess_type(filenameif contenttype =none or encoding is not nonecontenttype '?/?maintypesubtype contenttype split('/' if maintype ='textand subtype ='html'trywebbrowser(filename**optionselif maintype in mimetableplayknownfile(filenamemimetable[maintype]**optionselsetrywebbrowser(filename**optionscheck name can' guess poss txt gz 'image/jpegspecial case try table other types ##############################################################################self-test code ##############################################################################if __name__ ='__main__'media type known playknownfile('sousa au'audiotoolswait=trueplayknownfile('ora-pp gif'imagetoolswait=trueplayknownfile('ora-lp jpg'imagetoolsmedia type guessed input('stop players and press enter'playfile('ora-lp jpg'playfile('ora-pp gif'playfile('priorcalendar html'playfile('lp -preface-preview html'playfile('lp-code-readme txt'playfile('spam doc'playfile('spreadsheet xls'playfile('sousa au'wait=trueinput('done'image/jpeg image/gif text/html text/html text/plain app app audio/basic stay open if clicked although it' generally possible to open most media files by passing their names to web browser these daysthis module provides simple framework for launching media files with more specific toolstailored by both media type and platform web browser is used only as fallback optionif more specific tools are not available the net result is an extendable media file playerwhich is as specific and portable as the customizations you provide for its tables we've seen the program launch tools employed by this script in prior the script' main new concepts have to do with the modules it usesthe webbrowser module to open some files in local web browseras well as the python mimetypes module to complete system programs