Skip to content Skip to sidebar Skip to footer

How Do I Get Python To Read And Extract Words From A Text File?

So I need to make a code that opens a txt file, and then takes the content of that file and puts it into another txt file, problem is, I don't know how the command to extract the i

Solution 1:

A sample code to copy text from one file to another. Maybe it will help you:

inputFile = open("Input.txt","r")
text = inputFile.read()
inputFile.close()
outputFile = open("Output.txt","w")
outputFile.write(text)
outputFile.close()

Solution 2:

simple just try this

#openinput file andread all linesand save it in a list
fin = open("Input.txt","r")
f = fin.readlines()
fin.close()

#openoutput file andwrite all linesin it
fout = open("Output.txt","wt")
for i in f:
    fout.write(i)
fout.close()

Post a Comment for "How Do I Get Python To Read And Extract Words From A Text File?"