determining bytes read from a file.

John Machin sjmachin at lexicon.net
Thu Dec 13 07:38:35 EST 2007


On Dec 13, 11:04 pm, vineeth <nvine... at gmail.com> wrote:
> Hello all,
>    I have come across a weird problem, I need to determine the amount
> of bytes read from a file, but couldn't figure it out ,
>    My program does this :
> __
>    file = open("somefile")
>    data = file.read()
>    print "bytes read ", len(data)
> ---
>
>   But the bytes read is not being printed correctly, I think bytes are
> being counted only till the first occurance of '\0' is encountered.
> Even though the file is of a very large size, the bytes till the first
> '\0' are counted.

Python will not stop on reading '\0'. On Windows in text mode (the
default), '\r\n' will be converted to '\n', and it will stop on
reading ^Z aka chr(26) aka '\x1A'. If you don't want that to happen,
use open('somefile', 'rb') to get binary mode.



More information about the Python-list mailing list