Extract text around a list of words in python 3.x -
i extract few lines (perhaps 100 or characters) of text text files. have list of words extract around. have following code want except lines not long enough capture need.
import os ngwrds=[long list of words] filename in os.listdir(os.getcwd()): open(filename, 'r') searchfile: line in searchfile: if any(x in line x in ngwrds): open("extract.txt", 'a') out: out.write("{} {} \n".format(filename, line))
any thoughts? thank you.
Comments
Post a Comment