S
S
SaShATeR2021-09-15 17:05:26
Python
SaShATeR, 2021-09-15 17:05:26

Why might the write statement not work when writing to a text file in Python?

Hello, I'm learning Python, but when I got to the topic "Writing to text files", I ran into a problem. I wrote a program, saved it, ran it, and saw <<< and nothing else. And the main thing does not give errors.
Here is the code:

inputFile = open ('myfile.txt', 'r')
outputFile = open ('myoutputfile.txt', 'w')

msg ​​= inputFile.read(10)

while len(msg):
outputFile.write(msg
msg = inputFile.read(10) inputFile.close

()
outputFile.close()

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vindicar, 2021-09-15
@Vindicar

How did you launch the program?
Judging by the description, you are looking at the window of the interactive python interpreter.
It shouldn't run when you run the .py file, so either you're running it wrong, or your python installation is crooked.

S
SaShATeR, 2021-09-16
@SaShATeR

Launched in IDLE

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question