D
D
Dmitry2018-07-26 15:25:32
Python
Dmitry, 2018-07-26 15:25:32

Text is not being written to a text file?

Started learning Python. Looked at the lesson on working with files.
create a text document named 'text'. Next, I write the following code:
file = open ('text.txt', 'w')
file.write('Hello')
After that, the word 'Hello' should appear in the file, but it is not there. The python file and the document are in the same folder.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Kuts, 2018-07-26
@Kennyrnt

Buffer flush to disk then already:
The data is written first to the buffer. From which, in this case, when the file is closed, changes from the buffer are written to disk.

D
Dimonchik, 2018-07-26
@dimonchik2013

get used to context managers right away
with which
will help you in life more than once, and not only in Python

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question