Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding EOF

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hello everyone,

I've got a problem. I'ver tried to find the EOF but the programm didn't work!
Cann anyone help me?
The programm looks like this:
...
self.sourcefile = open(sourcefile, 'r')
...
lines = self.sourcefile.readlines()
...
for line in lines:
if not line: # but this matches not the EOF??!?!
print "---EOF---"
 
If you don't mind loading the whole file into memory at once, here's a quick way:

self.sourcefile = open(sourcefile, 'rb')
lines = self.sourcefile.read().split('\n')
for line in lines:
print line

Now, you don't have to detect EOF anymore !
 
If you don't mind loading the whole file into memory at once, here's a quick way:

self.sourcefile = open(sourcefile, 'rb')
lines = self.sourcefile.read().split('\n')
for line in lines:
print line

Now, you don't have to detect EOF anymore !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top