Reputation: 1
Here is some sample code:
def selectline(readfile,writefile,word):
readfile=open('problem3.txt','r')
lines=infile.read()
infile.close()
index=0
while index<len(lines):
lines[index]=str9lines[index]
for word in lines:
transfer=lines
Upvotes: 0
Views: 156
Reputation: 64845
What you're currently doing is iterating the file character-by-character; you do not want to do that.
Instead, you can iterate a file line by line this way:
for line in open('myfile.txt'):
...
and then you can check whether a line contains a certain string by doing:
if 'organic' in line:
...
and write those lines that you need:
outfile.write(line)
Upvotes: 1
Reputation: 172259
Here is a hint for you to get you a bit further:
for line in infile:
if text in line:
outfile.write(line)
Upvotes: 1