[Tutor] How to write strings with new line character in a file

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Fri Oct 13 18:53:32 CEST 2006


> fname = raw_input("Enter the file name to write data to:\t")
>
> fd = open(fname,'a+')
> print fd
> done = 0

Ok, good, that helps a lot: that's exactly what we need to diagnose the 
problem.  There appears to be something funky that happens with 
append-plus mode.  This problem has come up before on the list:

     http://aspn.activestate.com/ASPN/Mail/Message/python-tutor/2961494

In general, any of the '+' modes on a Windows platform is slightly broken. 
See:

     http://mail.python.org/pipermail/tutor/2006-September/049511.html

for approaches that people suggest to avoid "plus" mode issues.


More information about the Tutor mailing list