I open a file with :
mylog = open('test.log', 'w')
and sometimes some content is written in mylog
during the running time of my application ; but sometimes nothing is written during the running time of the app, it depends.
In both cases, it seems that the file test.log
is always created on disk.
Is there a way of writing the file to disk only when the first content is written into it ? (with something like mylog.write('blah')
for example)
i.e. if mylog.write('...')
is never called, then the (empty) file test.log
is not created on disk.