string - Keyword Search and exporting to output doc in .txt file in Python -


i'm trying write python function reads each individual line of text file , searches keyword: if keyword in line i'm trying make export line new text document. create way filter lines of text. here have far:

#trying filter , print line contains keyword in csv or txt   file import subprocess import csv  def findandsearch(word):     textfile=open('texthcpc17_contr_anweb.txt', 'r+')     #openign selected text file     outputfile=input('cmsoutput.txt')     #classifying ouput file     word=s'education' #designating keyword     line in textfile:         textfile.readline()         if word in textfile: #creating if clause             print('this match') #printing match              outputfile.write(word) #i want write selected line of text in output file             textfile.close() #closing original file             print(word) #i want print results             return #ending function 

any appreciated not running syntax error output file blank.

your loop should this:

for line in textfile:     if word in line:         print('blahblah')         outputfile.write(line)         textfile.close()         print(line)         return 

in if clause have comparison between string , file object , sounds weird :-s
in python documentation solution explained better: python doc - input , output


Comments

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -