[Tutor] file I/O

Massey, Craig Craig.Massey@oxygenforbusiness.com
Thu, 12 Jul 2001 08:35:39 +1200


Is there a "standard" way of removing the newline, like chomp in Perl?

-----Original Message-----
From: Michael P. Reilly
[mailto:arcege@dsl092-074-184.bos1.dsl.speakeasy.net]
Sent: Thursday, July 12, 2001 8:31 AM
To: kp87@lycos.com
Cc: tutor@python.org
Subject: Re: [Tutor] file I/O


kevin parks wrote
> 
> Hi. I am a little confused as to why this hangs when i run it. I am trying
to

Off hand, I would say it is the end condition.  The readline method
returns an empty string (false) when the end of file is reached, not a
string with a space.

> 	done = 0
> 	while not done:
> 		aLine = infile.readline()
> 		if aLine != " ":
                if aLine != "":  # not at EOF, so write out

> 			f.write(aLine + '\n')
> 		else:
> 			done = 1

Also, readline returns a whole line of text, including the newline.
You probably do not need to append an additional newline.

  -Arcege

-- 
+----------------------------------+-----------------------------------+
| Michael P. Reilly                | arcege@speakeasy.net              |

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

DISCLAIMER:  This electronic message together with any attachments is 
confidential.  If you are not the intended recipient, do not copy, disclose or 
use the contents in any way.  Please also advise us by return e-mail that you 
have received the message and then please destroy.  Carter Holt Harvey is not 
responsible for any changes made to this message and / or any attachments after 
sending by Carter Holt Harvey.  We use virus scanning software but exclude all 
liability for viruses or anything similar in this email or any attachment.