'Python skipping one line after reading another [duplicate]
I am trying to read a file and write its contents in another file.
with open (inputFile, "r+") as file:
with open (outputFile, "w+") as f:
for line in file:
data = file.readline()
f.write(data)
f.close()
file.close()
This is the code I used, but it seems to be skipping lines, so, if I have something like this in the input file:
'First line'
'Second line'
'Third line'
'Fourth line'
I get this in the outputFile:
'Second line'
'Fourth line'
What am I doing wrong?
Solution 1:[1]
for line in file iterates over each line already. data = file.readline() will yield another one from the file. Use one or the other.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | matszwecja |
