title: Python 2.7: "AttributeError: 'callable-iterator' object has no attribute 'group' " (regex finditer within generator expression)
body: <p>I'm writing a program that involves the following generator expression (as you might guess, 'sep2' is a compiled regular expression):</p>
  
  <pre><code>(chunk.group(1).strip(punctuation) for chunk in sep2.finditer(textString))
  </code></pre>
  
  <p>This works fine. However, it occurred to me that the program would be more scalable if instead of working with a big string, it worked through a file line by line. So I tried the following:</p>
  
  <pre><code>(chunk.group(1).strip(punctuation) for chunk in (sep2.finditer(line) for line in file))
  </code></pre>
  
  <p>Unfortunately, this throws the following error message:</p>
  
  <pre><code>AttributeError: 'callable-iterator' object has no attribute 'group'
  </code></pre>
  
  <p>Now, I could just give up on the idea of working through the file line by line - to be honest, it's not a big deal. But I'm curious to know what's going wrong here. I've searched stackoverflow (and the Python website, and the internet generally) for the error message above but haven't found anything that seems relevant. I think that what I need to know is how to get the match objects out of the 'callable-iterator' objects that the inner generator expression is (I presume) yielding. But I may just be confused; I'm not much of a programmer (just someone who finds programming useful)!</p>
  
  <p>Thanks for your time.</p>