I run into some new problems again. I'm trying to write line by line, according to a condition, into a new file from a file. I can print the lines that I need, but couldn't write it into a file. Here is what I write:
import os
with open('c:\\30001.txt', 'r',encoding= 'utf-8') as lines:
words_to_copy = set(line.rstrip() for line in lines)
print(len(words_to_copy))
#print(filenames_to_copy)
with open('c:\\long.txt', 'r',encoding= 'utf-8') as f:
for line in f:
if(line.split(None, 1)[0]) in words_to_copy:
with open("c:\\3000line.txt", "w", encoding ='utf-8') as the_file:
the_file.write(line) # It runs for minutes not nothing in the new file.
#print(line) #It can print lines that I need.
Many thanks!