[Tutor] A further question about opening and closing files

richard kappler richkappler at gmail.com
Wed Sep 9 17:40:07 CEST 2015


Thanks, tried them both, both work great on Linux. Now I understand better.

regards, Richard

On Wed, Sep 9, 2015 at 11:28 AM, Laura Creighton <lac at openend.se> wrote:

> >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
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>



-- 

All internal models of the world are approximate. ~ Sebastian Thrun


More information about the Tutor mailing list