I'm trying to read a file containing instructions for a turtle robot in micropython on the BBC micro bit but when I flash my code and add the correct files it just hangs and doesn't seem to do anything. It runs fine in python on my machine. Is micropython missing something I am doing but not telling me?
Here is the relevant code. A class is defined underneath this function but I haven't included that code as it's irrelevant to this bit.
def processInstFile(fileName):
writeBuffer = []
writeBuffer.append("myturtle = turtle()\n")
with open(fileName,'r') as instFile:
for line in instFile:
line=line.strip()
if line[0] == "#":
pass
else:
if line.find("mf") != -1:
writeBuffer.append("myTurtle.moveForward("+line[3:]+")\n")
if line.find("mb") != -1:
writeBuffer.append("myTurtle.moveBackward("+line[3:]+")\n")
if line.find("t") != -1:
writeBuffer.append("myTurtle.turnAngle("+line[2:]+")\n")
if line.find("pu") != -1:
writeBuffer.append("myTurtle.penUp()\n")
if line.find("pd") != -1:
writeBuffer.append("myTurtle.penDown()\n")
with open("turtleScript.py",'w') as instOutput:
for line in writeBuffer:
instOutput.write(line)
return
processInstFile("turtleinstr.py.p8l")
display.show(Image.HEART)