add the next Boggle part.
This commit is contained in:
parent
7cf4d90336
commit
9214cdea09
2 changed files with 140 additions and 3 deletions
23
Boggle/interpreter.py
Normal file
23
Boggle/interpreter.py
Normal 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])
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue