Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

readln() until EOF

 

 

Python python RSS feed   Index | Next | Previous | View Threaded


davidreynon at gmail

Jul 24, 2008, 12:09 PM

Post #1 of 3 (283 views)
Permalink
readln() until EOF

a = open("Thefile.txt","r")

while ?????:
result = a.readln()

what do i put in ???? if i want to keep reading line by line until i
reach the end of the file?

I don't want to break the loop if there is a blank line, because there
will be.

Ex. of a file:

map1
result1

map2
result 2

map3
result3
comments

thanks...
--
http://mail.python.org/mailman/listinfo/python-list


diordna at gmail

Jul 24, 2008, 12:12 PM

Post #2 of 3 (278 views)
Permalink
Re: readln() until EOF [In reply to]

the_file = open(path, 'r')
for this_line in the_file:
#do stuff with this_line

-Steve Johnson

On Jul 24, 2008, at 3:09 PM, korean_dave wrote:

> a = open("Thefile.txt","r")
>
> while ?????:
> result = a.readln()
>
> what do i put in ???? if i want to keep reading line by line until i
> reach the end of the file?
>
> I don't want to break the loop if there is a blank line, because there
> will be.
>
> Ex. of a file:
>
> map1
> result1
>
> map2
> result 2
>
> map3
> result3
> comments
>
> thanks...
> --
> http://mail.python.org/mailman/listinfo/python-list


bdesth.quelquechose at free

Jul 24, 2008, 12:25 PM

Post #3 of 3 (260 views)
Permalink
Re: readln() until EOF [In reply to]

korean_dave a écrit :
> a = open("Thefile.txt","r")
>
> while ?????:
> result = a.readln()

I assume you meant "a.readline()" ? Anyway...

> what do i put in ???? if i want to keep reading line by line until i
> reach the end of the file?

a = open("path/to/file.ext")
for line in a:
do_something_with(line)
a.close()

--
http://mail.python.org/mailman/listinfo/python-list

Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.