[Tutor] deleting CR within files

David Talaga dtalaga at novodynamics.com
Sat Apr 17 12:57:35 EDT 2004


Actually I changed it even more since last.

for i in in_file:
      out_file.write(i[:])

This does what I need with the excpetion that it dosent do it for every
line.  It is currous because it will take off a <cr> from one line and not
the next 2 and then from another line...  currious...

-----Original Message-----
From: Alan Gauld [mailto:alan.gauld at blueyonder.co.uk]
Sent: Saturday, April 17, 2004 12:48 PM
To: David Talaga; Roger Merchberger; tutor at python.org
Subject: Re: [Tutor] deleting CR within files



> From the last post I sent I said that the problem is in the for
statement. I
> still think that.  But how would I take out the extra <cr>'s?

>      fileName=dialog.dialog()
>      in_file = open(fileName,'r').readlines()
>      out_file = open(fileName + '_cleaned', 'w')
>      for i in in_file: #Changed the for statement to say in_file
(duh!)
>         out_file.write(i[:-1] + '\n') #maybe the problem is here?

What happens if you don't put the \n back on?
As it stands you are stipping off one character with the [:-1]
and putting another on with the +'\n'. Maybe just leaving
off the \n will do what you want?

>   root.mainloop()

BTW The Tkinter stuff is doing nothing useful so far, it's
just adding confusion to the code. You might be better
stripping it out until you are ready to use it.

Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld




More information about the Tutor mailing list