Skipping EOFs when using file objects?

Chad Netzer cnetzer at mail.arc.nasa.gov
Wed Nov 27 22:20:46 EST 2002


On Wednesday 27 November 2002 18:32, Colin Cashman wrote:
> I'm building a decoder for yEnc files, but I'm hitting premature EOF
> characters (that is, I'm only 300 or 400 bytes into the file, when the
> file size is around 950 bytes).

Are you sure you are opening your files as binary?  If you are using Windows, 
you probably have to explicitly state it (and it is wise to do it anyway, to 
be explicit about it)

ie:

f = file( "my_file.ync", 'rb' )

When you get an EOF in binary mode (on any sane operating system, which is 
nearly all these days), it isn't a "character" in the file, but a result of 
metadata (contained outside the file) informing you when the file has no more 
characters to read.  So, you can't 'skip' over them; there would be no more 
data to skip to.

I suspect you are either encountering a 'text-mode' file processing problem 
(whixh is fixed by the above), or you are mistaken about what your code 
actually does and how much it actually reads.  So, post a follow up if it 
isn't cured by binary mode.

-- 
Bay Area Python Interest Group - http://www.baypiggies.net/

Chad Netzer
cnetzer at mail.arc.nasa.gov




More information about the Python-list mailing list