text.concordance(self, word, width=79, lines=25) seems to have other parameters as per the manual .
I see no way to extract the concordance index, however, the concordance printing code seems to have this part: lines = min(lines, len(offsets)) , so you can just pass sys.maxint as the last argument:
concord = text.concordance("cultural", 75, sys.maxint)
Added:
Now, looking at your original code, I donβt see the way it could work before. text.concordance nothing, but prints everything to stdout with print . So a simple option would be to redirect stdout to your file, for example:
import sys ....
Another option is to use the appropriate classes directly and omit the text wrapper. Just copy the bits from here and combine them with the bits here , and you're done.
source share