Using findAll(): 'NoneType' object is not iterable? --- only one iteration possible!

Asked by Rhys

here is the message:
[profile] Finder.findAll START
[profile] Finder.findAll END: 497ms
[profile] Finder.findAll START
[profile] Finder.findAll END: 509ms
[profile] Finder.findAll START
[profile] Finder.findAll END: 537ms
[profile] Finder.findAll START
[profile] Finder.findAll END: 516ms [error] Stopped [error] An error occurs at line 2 [error] Error message: Traceback (most recent call last): File "C:\Users\.....\AppData\Local\Temp\sikuli-tmp8434612038004279852.py", line 2, in for x in findAll(Pattern("I.png").similar(0.81)): TypeError: 'NoneType' object is not iterable

and here is the code:
setFindFailedResponse(SKIP)
for x in findAll(img1 ):
 setFindFailedResponse(SKIP)
 click(x)
 wait(2)
 click(image2 )
 wait(2)
 while exists(image3 ):
  sleep(5)
for x in findAll(image1a):
 click(x)
 wait(2)
 click(image2 )
 wait(2)
 while exists(image3 ):
  sleep(5)

why is it that i am geting a 'NoneType' object is not iterable? error

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

If you want to iterate more than once thru your matches after findAll(), you have to save the matches into a list first.
An iterator can only be used once.

look: http://sikuli.org/docx/region.html#Region.findAll
and: http://sikuli.org/docx/finder.html#finder

Revision history for this message
Zubin Sethna (zubinix) said :
#2

I'm working in Jruby and have come across a similar problem. Basically I do a findAll e.g

myMatches = someRegion.findAll(somePattern)

If I call the "count" method on myMatches first then I cannot iterate through the matches later. It seems that the count method actually uses the iterator so I can't use it later!

Is this correct and how do I get the number of matches? Do I have to copy into an array first?

Thanks

Zubin

Revision history for this message
RaiMan (raimund-hocke) said :
#3

@Zubin
as mentioned in comment #1, every walk through the iterator makes it empty.
… count has to walk through, I guess.

Can you help with this problem?

Provide an answer of your own, or ask Rhys for more information if necessary.

To post a message you must log in.