[Tutor] Tutor Digest, Vol 32, Issue 49

Meher Kolli meherkp at gmail.com
Fri Oct 13 10:55:41 CEST 2006


>
> Message: 8
> Date: Fri, 13 Oct 2006 02:03:49 +0100
> From: "Asrarahmed Kadri" <ajkadri at googlemail.com>
> Subject: [Tutor] How to write strings with new line character in a
>         file
> To: pythontutor <tutor at python.org>
> Message-ID:
>         <b4e894c70610121803m356f6c5dl14a8bf9688fdc691 at mail.gmail.com>
> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20061013/a3021be6/attachment.html 


More information about the Tutor mailing list