Here is a very basic object orientated implementation of a read evaluate print loop AKA REPL. I encluded REShell
to demonstrate how one could use Reple
#-*-coding:utf8;-*- #qpy:3 #qpy:console import re import sre_constants PS1 = '>> ' DEFAULT_EVALUATOR = print class Reple(object): def __init__(self, evaluator=DEFAULT_EVALUATOR): self.ps1 = PS1 self.evaluator = evaluator def read(self): return input(self.ps1) def evaluate(self): return self.evaluator(self.read()) def run(self): while 1: try: self.evaluate() except KeyboardInterrupt: sys.exit(0) class REShell(Reple): def __init__(self, data): self.data = data self.ps1 = PS1 def evaluate(self): try: expression = re.compile(self.read()) print(*expression.findall(self.data), sep='\n') except sre_constants.error as error: print(error) def source_code(): with open(__file__, 'r') as source: return source.read() if __name__ == '__main__': data = source_code() print(data) shell = REShell(data) shell.run()