# Opens a text file and reads instructions for the robot from it, executing the # instructions # # Released to the public domain June 2007 # Jay Summet # #Process A line def processLine(myLine): #Process the Line print "myLine is: ", myLine #split the line into parts. import string listLine = string.split(myLine," ") print "split into parts", listLine #Check, is it a valid number? myNumber = 0 try: myNumber = float(listLine[1] ) except: print "Number is invalid!" return() print "my number is:", myNumber #YES, do one of 3 commands: if (listLine[0] == 'forward'): print "Go Forward for ", myNumber, " seconds!" #forward(1.0,myNumber) elif (listLine[0] == 'left'): print "Turn Left for ", myNumber, " of seconds!" #turnLeft(1.0,myNumber) elif (listLine[0] == 'right'): print "Turn right for", myNumber, " of seconds!" #Otherwise, if the command is invalid... else: print "Error! ", listLine[0], "is a bad command!" #Initialize things: try: f = open("myFile.txt","r") except: print "File Not Found!" #Loop through each line myLine = f.readline() while (len(myLine) > 0): processLine(myLine) myLine = f.readline() # Cleanup f.close()