determining bytes read from a file.

vineeth nvineeth at gmail.com
Thu Dec 13 07:39:54 EST 2007


On Dec 13, 5:27 pm, Marc 'BlackJack' Rintsch <bj_... at gmx.net> wrote:
> On Thu, 13 Dec 2007 04:04:59 -0800, vineeth wrote:
> >    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.
>
> If you want to deal with bytes better open the file in binary mode.
> Windows alters line endings and stops at a specific byte (forgot the
> value) otherwise.
>
> Ciao,
>         Marc 'BlackJack' Rintsch

Thanks, opening the file in binary mode helped, thanks a lot.



More information about the Python-list mailing list