Python does not immediately writes to the file?

I Use Python3. Task to write data to a file and to send a signal about their readiness. The other program opens the file and it is empty.
Rummaged on forums added a line ftxt.flush() - nothing has changed.
He delved further, he added os.fsync(ftxt.fileno()) - in file has data, but not all. Put a delay of 5 seconds - the amount of recorded data has not changed.

Tried txt = open(name,"w",0) - python error ValueError("can't have unbuffered text I/O"). It was said that because of the Unicode in python3 to open the file without a buffer impossible.
Tried another print(name,file=ftxt,flush=True) - did not help!

Here is the code:
ftxt = open(name, 'w')
import time

import socket

PORT = 33333
IP = ""

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
msg = "User::Git.load_in \"" + name + "\""
sock.sendto(msg.encode('utf-8'), (IP, PORT))

Are there any ideas?
July 8th 19 at 12:21
2 answers
July 8th 19 at 12:23
# -*- coding: utf-8 -*-
In python3 do not have - Whitney commented on July 8th 19 at 12:26
July 8th 19 at 12:25
Try to acrivate file for writing in binary mode

Find more questions by tags Python