Index: Lib/idlelib/EditorWindow.py =================================================================== --- Lib/idlelib/EditorWindow.py (revision 76258) +++ Lib/idlelib/EditorWindow.py (working copy) @@ -17,6 +17,10 @@ from configHandler import idleConf import aboutDialog, textView, configDialog import macosxSupport +try: + import _winreg +except ImportError: + _winreg = None # The default tab setting for a Text widget, in average-width characters. TK_TABWIDTH_DEFAULT = 8 @@ -600,10 +604,17 @@ base, ext = os.path.splitext(os.path.basename(filename)) if os.path.normcase(ext) in (".py", ".pyw"): return True + if ext and _winreg: + try: + with _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT, ext) as key: + ftype = _winreg.QueryValueEx(key, None)[0] + if ftype.lower() in ('python.file','python.noconfile'): + return True + except WindowsError: + pass try: - f = open(filename) - line = f.readline() - f.close() + with open(filename) as f: + line = f.readline() except IOError: return False return line.startswith('#!') and line.find('python') >= 0