MCPcopy Index your code
hub / github.com/python/cpython / execfile

Method execfile

Lib/idlelib/pyshell.py:660–678  ·  view source on GitHub ↗

Execute an existing file

(self, filename, source=None)

Source from the content-addressed store, hash-verified

658 self.execfile(filename, source)
659
660 def execfile(self, filename, source=None):
661 "Execute an existing file"
662 if source is None:
663 with tokenize.open(filename) as fp:
664 source = fp.read()
665 if use_subprocess:
666 source = (f"__file__ = r'''{os.path.abspath(filename)}'''\n"
667 + source + "\ndel __file__")
668 try:
669 code = compile(source, filename, "exec")
670 except (OverflowError, SyntaxError):
671 self.tkconsole.resetoutput()
672 print('*** Error in script or command!\n'
673 'Traceback (most recent call last):',
674 file=self.tkconsole.stderr)
675 InteractiveInterpreter.showsyntaxerror(self, filename)
676 self.tkconsole.showprompt()
677 else:
678 self.runcode(code)
679
680 def runsource(self, source):
681 "Extend base class method: Stuff the source in the line cache first"

Callers 2

execsourceMethod · 0.95
mainFunction · 0.80

Calls 8

runcodeMethod · 0.95
resetoutputMethod · 0.80
showpromptMethod · 0.80
compileFunction · 0.50
openMethod · 0.45
readMethod · 0.45
abspathMethod · 0.45
showsyntaxerrorMethod · 0.45

Tested by

no test coverage detected