Wednesday 25 December 2019

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 information from the file, I did some research and found this is the closest thing but It just isn't what I need: How do I get python to read only every other line from a file that contains a poem



this is my code so far:




myFile = open("Input.txt","wt")
myFile.close()
myFile = open("Output.txt","wt")
myFile.close()

Answer



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()

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...