Message: 8
Date: Fri, 13 Oct 2006 02:03:49 +0100
From: "Asrarahmed Kadri" < [EMAIL PROTECTED]>
Subject: [Tutor] How to write strings with new line character in a
        file
To: pythontutor <[email protected] >
Message-ID:
        <[EMAIL PROTECTED]>
Content-Type: text/plain; charset="iso-8859-1"

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...

You can't  add  \n  to  a string ..up have  use something like this

   if str == 'q':
       done = 1
       fd.close()
   else:
       fd.write("%s \n" %(str)) 


--
Meher Kolli
Sunnyvale,CA-94085
_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to