I dont understand why, when i run my code the for each loop under the if statement isn’t run. Even when the number of found is greater than 0!
def findpattern(commit_msg):
pattern = re.compile("\w\w*-\d\d*")
group = pattern.finditer(commit_msg)
found = getIterLength(group)
print found
if found > 0:
issues = 0
for match in group:
print " print matched issues:"
auth = soap.login(jirauser,passwd)
print match.group(0)
getIssue(auth,match.group(0))
issues = issues + 1
else:
sys.exit("No issue patterns found.")
print "Retrieved issues: " + str(issues)
Any help would be appreciated, I have been banging my head on this for an hour.
Your
getIterLength()function is finding the length by exhausting the iterator returned byfinditer(). You would then need a new iterator instance for the for loop. Instead, I would restructure your code like this:OR, you could use the
findall()method instead offinditer()to give you a list (which is an iterable, not an iterator) on which you can runlen(group)to get the size and then use it to iterate over in your for loop.