load fileand will evaluate all the expressions defined in the file. This will be especially useful if you want to test longer Charme programs in your evaluator.
def evalLoop(): print "Welcome to Charme (the Snake Charmer's Language)" initializeGlobalEnvironment() while True: intext = raw_input("Charme> ") commands = intext.split() if commands[0] == 'quit': break elif commands[0] == 'load': if len(commands) != 2: print "Load commands expects one parameter." continue else: fname = commands[1] try: f = open(fname) intext = f.read() except: print "Error reading file: " + fname try: exprs = parse(intext) if exprs: for expr in exprs: res = meval(expr, globalEnvironment) if isinstance(res, Procedure): print res.toString() elif res != None: print res except: print "Error evaluating " + str(expr)