Python 错误(无限循环或其他原因),导致代码中途停止在shell中运行

Python 错误(无限循环或其他原因),导致代码中途停止在shell中运行,python,python-imaging-library,pillow,Python,Python Imaging Library,Pillow,虽然我不能确切地说出原因是什么,但代码中的某些内容导致它中途停止运行,使shell处于一种状态,我可以单击一行、键入、按enter等。但是shell本身没有给我任何反应 完整代码如下: from PIL import Image import PIL.ImageOps background = "background.png" target = input("Please enter the name of your image (including file type)") targetI

虽然我不能确切地说出原因是什么,但代码中的某些内容导致它中途停止运行,使shell处于一种状态,我可以单击一行、键入、按enter等。但是shell本身没有给我任何反应

完整代码如下:

from PIL import Image
import PIL.ImageOps


background = "background.png"
target = input("Please enter the name of your image (including file type)")
targetImage = Image.open(target)
background = Image.open(background)
area = targetImage.size 
backArea = background.size
area = (round(area[0] / 500), round(area[1] / 500))
backArea = (round(backArea[0] / 100), round(backArea[1] / 100))
targetImage = targetImage.resize(area)
background = background.resize(backArea)
size = area[0] * area[1]
targetWidth = area[0]
targetLength = area[1]

targetCoords = []


def analyser():
    pixelOne = 1
    pixelTwo = 1
    completedSearch = 0


    while completedSearch != size:
        while pixelOne != targetWidth:
            while pixelTwo != targetLength:
                targetCoords.append((pixelOne, pixelTwo))
                pixelTwo = pixelTwo + 1
                completedSearch = completedSearch + 1
            pixelTwo = 1
            pixelOne = pixelOne + 1


    colouredCoordsSum = []
    largerColouredCoordsSum = []
    smallerColouredCoordsSum = []
    flatTargetCoords = [x for sets in targetCoords for x in sets]
    coordLength = len(flatTargetCoords) - 1
    for i in range(0, coordLength, 2):
        firstnum = flatTargetCoords[i]
        secondnum = flatTargetCoords[i+1]
        sumnum = firstnum + secondnum
        if firstNum > secondNum:
            largerColouredCoordsSum.append("(",firstNum,", ",secondNum,"), (",sumnum,")")
        else:
            smallerColouredCoordsSum.append("(",firstNum,", ",secondNum,")")
        colouredCoordsSum.append(sumnum)

    global topLeft
    global bottomRight
    global topRight
    global bottomLeft
    topLeft = min(smallerColouredCoordsSum)
    bottomRight = max(largerColouredCoordsSum)
    topRight = topLeft + (area[0] - 1)
    bottomLeft = bottomRight - (area[1] - 1)


analyser()
print(topLeft, topRight, bottomLeft, bottomRight)
我认为代码的问题在于第一个while循环的内容:

while completedSearch != size:
        while pixelOne != targetWidth:
            while pixelTwo != targetLength:
                targetCoords.append((pixelOne, pixelTwo))
                pixelTwo = pixelTwo + 1
                completedSearch = completedSearch + 1
            pixelTwo = 1
            pixelOne = pixelOne + 1
也就是说,可能还有其他错误导致了这种情况。由于代码在此状态下不能在shell中完全运行,因此我无法在删除错误方面取得进展。感谢您的帮助

编辑:当我运行代码时,会收到输入提示,但在键入文件名并按enter键后,我看不到任何东西在运行,也看不到下一行的“>>>”,但我可以在空行之间单击,在这些行上键入,然后按enter键,但shell不会对我在该状态下键入的任何内容做出反应。完成后,应将每个角的坐标打印到外壳上,但不会出现

while completedSearch != size:
    while pixelOne != targetWidth:
        while pixelTwo != targetLength:
            targetCoords.append((pixelOne, pixelTwo))
            pixelTwo = pixelTwo + 1
            completedSearch = completedSearch + 1
        pixelTwo = 1
        pixelOne = pixelOne + 1

当这个循环开始时,如果
completedSearch
大于
size
,或者
pixelOne
大于
targetWidth
,或者
pixelTwo
大于
targetLength
,它将永远不会退出。

它应该是等效的,但在这种情况下,如果说completedSearchcompletedSearch==size时结束,但是如果
completedSearch>size
,你也希望它不运行,因此你的条件应该是
,而completedSearch