Newbie looking for feedback
Tyler Eaves
tyler at tylereaves.com
Fri Sep 15 00:51:12 EDT 2000
On Fri, 15 Sep 2000 04:43:52 GMT, David Lees
<debl.spamnono at world.std.com> wrote:
Still sorta a newbie myself, but here's my take.
in=open('C:\\foo.txt','r').readlines()
#Opens the input file and reads each line into a list entry
out=open('C:\\bar.txt','w')
#Open output file
for x in in[:]:
#Loop once for every line
if len(x)>1:
#Test to see if the line has anything....
out.write(x)
#It does! Write it!
#Done!
(5 lines of active code that gets the job done!)
>Two questions. First, I have written a real simple Python routine to
>remove blank lines from a text file. The code below works but...
>
>1. I am sure this can be written much more simply, any hints?
>2. Could someone point me to documentation or tell me how to use IDLE
>under Windows to single step through the code. It was a pain debugging
>by executing the whole script as a run module command to IDLE.
>
>Thanks in advance.
>
>david lees
>
>
>import string
>
>fin=open("c:\\foo.txt","r")
>fout=open("c:\\barf.txt","w")
>s=""
>
>while 1:
> nextln=fin.readline()
>
> if len(nextln)==0 :
> break
>
> if nextln[0] != '\n' :
> fout.write(nextln)
>
>fin.close()
>fout.close()
---
Tyler Eaves
Visit Ultra Coaster Central!
The internet's largest repository
of Ultra Coaster Tracks!
http://www.ultracoastercentral.com
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 80,000 Newsgroups - 16 Different Servers! =-----
More information about the Python-list
mailing list