Skipping EOFs when using file objects?

Bengt Richter bokr at oz.net
Wed Nov 27 22:51:21 EST 2002


On Thu, 28 Nov 2002 02:32:10 GMT, Colin Cashman <ccashman at attbi.com> 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).
>
>Is there any way, without resorting to file descriptor operations, to 
>configure a file object such that it skips over those premature EOF 
>characters?
>
It sounds like you need to open the file in binary (mode 'rb').
Otherwise ctrl-z will look like eof, not to mention other possible
mixups.

 >>> f=file('test.dat','wb')
 >>> f.write('This probably will end here:\x1a\And not show this')
 >>> f.close()
 >>> file('test.dat').read()
 'This probably will end here:'
 >>> file('test.dat','rb').read()
 'This probably will end here:\x1a\\And not show this'

Regards,
Bengt Richter



More information about the Python-list mailing list