[Tutor] A further question about opening and closing files
Laura Creighton
lac at openend.se
Wed Sep 9 17:28:21 CEST 2015
>I did a little experiment:
>
>>>> f1 = open("output/test.log", 'a')
>>>> f1.write("this is a test")
>>>> f1.write("this is a test")
>>>> f1.write('why isn\'t this writing????')
>>>> f1.close()
If you want the thing written out, use f1.flush() whenever you want to
make sure this happens.
If you want completely unbuffered writing, then you can open your file
this way, with f1 = open("output/test.log", 'a', 0) I think if you are
on windows you can only get unbuffered writing if you open your file
in binary mode.
Laura
More information about the Tutor
mailing list