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
Here is a hint for you to get you a bit further:
for line in infile:
if text in line:
outfile.write(line)
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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.