0
findAll(Pattern("excel_icon.png").similar(0.9))
nn = getLastMatches()
print "nn -> ",list(nn)
while nn.hasNext():
    print "excel --> ",nn.next()

以上是代码。在这里,我尝试在桌面上找到所有的MS excel图标,然后将其一一打印出来。当我运行它时,在 sikuli 的消息框中只能看到第 3 行代码的输出,并且没有打印第 5 行。输出:-

nn -> [Match[470,936 53x56 score=0.98 target=center], Match[394,936 53x56 score=0.98 target=center]

但是,当我在第三行替换list(nn)nn

print "nn -> ",nn

我得到的输出是: -

nn -> org.sikuli.script.Finder@4b0431
excel --> Match[470,936 53x56 score=0.98 target=center]
excel --> Match[394,936 53x56 score=0.98 target=center]

我很困惑为什么当我在第 3 行使用 line() 时它没有打印第 5 行。谁能帮帮我??

4

1 回答 1

1

getLastMatches() returns object of class Finder which is an Iterator.

Following code:

print "nn -> ",list(nn)

iterates nn while

print "nn -> ",nn

doesn't iterate.

That's why nn.hasNext() returns false after executing list(nn) first. To understand it better, run while twice like this:

print "first while"
while exfind.hasNext():
    print "excel --> ",exfind.next()
print "second while"
while exfind.hasNext():
    print "excel --> ",exfind.next()

There will be nothing displayed after "second while".

于 2013-05-17T10:01:14.900 回答