-1

I want to write to the file in real time(instead of waiting for the code to finish) by flushing, but it doesn't seem to change anything. Here's the code:

 dataFile =open("json",'a+')

 def write(data):
        dataFile.write(data)
        dataFile.flush()

also dataFile.close() didn't change anything. Does anyone know what the problem is?

EDIT: I managed to make it work by adding os.fsync(dataFile.fileno()) right after dataFile.flush()

Tom Giro
  • 1
  • 1

1 Answers1

0

You must use the standard Python library for JSON https://docs.python.org/3.3/library/json.html

I think the use of open file inside the function by the global name is not correct.

Sergey Nosov
  • 350
  • 3
  • 10