Problem Prompt: write all file content into new file by skipping line 5 from following file.
Testfile:
line1
line2
line3
line4
line5
line6
line7
newFile:
line1
line2
line3
line4
line6
line7
Code:
testFile = 'C:/Users\Karan\Documents\\test.txt'
newFile = 'C:/Users\Karan\Documents\\newtext.txt'
for num, line in enumerate(testFile, 1):
if num != 5:
newFile.write(line)
Errors:
Traceback (most recent call last):
File "C:/Users/Karan/AppData/Roaming/JetBrains/PyCharm2020.1/scratches/scratch_1.py", line 7, in <module>
newFile.write(line)
AttributeError: 'str' object has no attribute 'write'
I know it's an issue with the last line, But I've been pounding away at it all day and would really like a fresh set of eyes to look into it.