diff --git a/Lib/turtledemo/__main__.py b/Lib/turtledemo/__main__.py index 7c2d753f4c31113..4b7f2814b75e5ad 100644 --- a/Lib/turtledemo/__main__.py +++ b/Lib/turtledemo/__main__.py @@ -85,6 +85,7 @@ """ import sys import os +import tokenize from tkinter import * from idlelib.colorizer import ColorDelegator, color_config @@ -333,7 +334,7 @@ def loadfile(self, filename): modname = 'turtledemo.' + filename __import__(modname) self.module = sys.modules[modname] - with open(self.module.__file__, 'r') as f: + with tokenize.open(self.module.__file__) as f: chars = f.read() self.text.delete("1.0", "end") self.text.insert("1.0", chars) diff --git a/Misc/NEWS.d/next/Library/2026-07-08-19-40-00.gh-issue-153319.Qk7bE2.rst b/Misc/NEWS.d/next/Library/2026-07-08-19-40-00.gh-issue-153319.Qk7bE2.rst new file mode 100644 index 000000000000000..b67b124dc575928 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-07-08-19-40-00.gh-issue-153319.Qk7bE2.rst @@ -0,0 +1,3 @@ +The :mod:`turtledemo` viewer now reads each demo script using +:func:`tokenize.open`, decoding it with the encoding detected from the +source file.