Python:无错误地执行脚本,什么都不做

时间:2016-08-31 20:14:49

标签: python python-3.x

#!/usr/bin/python
import turtle

class GoToCommand:
    def __init__(self,x,y,width=1,color="black"):
        self.x = x
        self.y = y
        self.color = color
        self.width = width

    def draw(self,turtle):
        turtle.width(self.width)
        turtle.pencolor(self.color)
        turtle.goto(self.x,self.y)

class CircleCommand:
    def __init__(self,radius, width=1,color="black"):
        self.radius = radius
        self.width = width
        self.color = colorO

    def draw(self,turtle):
        turtle.width(self.width)
        turtle.pencolor(self.color)
        turtle.circle(self.radius)

class BeginFillCommand:
    def __init__(self,color):
        self.color = color

    def draw(self,turtle):
        turtle.fillcolor(self.color)
        turtle.begin_fill()

class EndFillCommand:
    def __init__(self):
        pass

    def draw(self,turtle):
        turtle.end_fill()

class PenUpCommand:
    def __init__(self):
        pass

    def draw(self,turtle):
        turtle.penup()

class PenDownCommand:
    def __init__(self):
        pass

    def draw(self,turtle):
        turtle.pendown()

class PyList:
    def __init__(self):
        self.items = []

    def append(self,item):
        self.items = self.items + [item]

    def __iter__(self):
        for c in self.items:
            yield c

def main():
    filename = input("Insert File Name: ")

    t = turtle.Turtle()
    screen = t.getscreen()
    file = open(filename, "r")


    graphicsCommands = PyList()

    command = file.readline().strip()

    while command != "":

        if command == "goto":
            x = float(file.readline())
            y = float(file.readline())
            width = float(file.readline())
            color = file.readline().strip()
            cmd = GoToCommand(x,y,width,color)

        elif command == "circle":
            radius = float(file.readline())
            width = float(file.readline())
            color = file.readline().strip()
            cmd = CircleCommand(radius,width,color)

        elif command == "beginfill":
            color = file.readline().strip()
            cmd = BeginFillCommand(color)

        elif command == "endfill":
            cmd = EndFillCommand()

        elif command == "penup":
            cmd = PenUpCommand()

        elif command == "pendown":
            cmd = PenDownCommand()
        else:

        # printed.
            raise RuntimeError("Unknown Command: " + command)

            graphicsCommands.append(cmd)

            command = file.readline().strip()

        for cmd in graphicsCommands:
            cmd.draw(t)

            file.close()
            t.ht()
            screen.exitonclick()
            print("Program Execution Completed.")

    if __name__ == "__main__":

        main()

我已经查找了我需要包含,移动,添加/删除的内容。它仍然无法正常运行。它就像主要的不存在一样。

1 个答案:

答案 0 :(得分:2)

缩进错误,修复如下 ....

        print("Program Execution Completed.")

if __name__ == "__main__":

    main()