-6

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()
Community
  • 1
  • 1
B0neCh3wer
  • 1
  • 1
  • 6
  • You might have missed "[Reading and Writing Files](https://docs.python.org/3/tutorial/inputoutput.html#reading-and-writing-files)" in the tutorial. – Matthias Dec 02 '16 at 12:52

2 Answers2

4

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()
Kryguu
  • 68
  • 5
1

simple just try this

#open input file and read all lines and save it in a list
fin = open("Input.txt","r")
f = fin.readlines()
fin.close()

#open output file and write all lines in it
fout = open("Output.txt","wt")
for i in f:
    fout.write(i)
fout.close()
Shivkumar kondi
  • 6,458
  • 9
  • 31
  • 58
  • This one should be the answer to this very basic question as he wants to extract words. It provides a structure that can be further used with e.g. regex to split on `" "` characters and process individual words in each line. The accepted answer could as well be `shutil.copyfile("Input.txt", "Output.txt")` – jaaq Nov 09 '18 at 14:53