Completed the insert functions.

This commit is contained in:
Charles Descamps 2025-02-15 23:38:41 -07:00
parent 7ce4c6c5ae
commit 54477a4266
3 changed files with 85 additions and 2 deletions

View file

@ -0,0 +1,23 @@
import code
import re
class FileConsole(code.InteractiveConsole):
"""Emulate python console but use file instead of stdin"""
def raw_input(self, prompt):
line = self.f.readline()
if line=="":
raise EOFError()
no_newline = line.replace("\n", "")
no_indent = re.match(r"^\s", line) is None
print(prompt, no_newline, sep="")
return no_newline
def run_file(filename):
fc = FileConsole()
fc.f = open(filename)
fc.interact(banner="", exitmsg="")
if __name__ == "__main__":
import sys
sys.ps1 = "\n>>> "
run_file(sys.argv[1])