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

Asrarahmed Kadri ajkadri at googlemail.com
Fri Oct 13 03:03:49 CEST 2006


Folks,

I am trying to enter names in a file; each on a new line with this code, but
not working:

done = 0
*while not done:
    str = raw_input("Enter login name:\t to quit type 'q': ")
    if str == 'q':
        done = 1
    else:  *
*       str = str + '\n'*
*       fd.write(str)
*
The traceback is as under:

Traceback (most recent call last):
  File "scrap.py", line 38, in ?
    fd.write(str)
IOError: (0, 'Error')

Please help to rectify this error...
-- 
To HIM you shall return.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20061013/c61223aa/attachment.html 


More information about the Tutor mailing list