add the next Boggle part.

This commit is contained in:
Charles Descamps 2025-02-02 15:11:51 -07:00
parent 7cf4d90336
commit 9214cdea09
2 changed files with 140 additions and 3 deletions

23
Boggle/interpreter.py Normal file
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])