Answer the question
In order to leave comments, you need to log in
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
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.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question