[Tutor] Windows problem with large(?) files

johan nilsson johanpo at googlemail.com
Thu Feb 2 13:12:08 CET 2006


Thanks Danny!

that solved it.

Johan

On 2/2/06, Danny Yoo <dyoo at hkn.eecs.berkeley.edu> wrote:
>
>
>
> On Thu, 2 Feb 2006, johan nilsson wrote:
>
>
> > apparently the XP box thinks the file is alot shorter, and that can't be
> > as it is the same file from the same media (USB stick). What is going
> > wrong here?
>
> Hi Johan,
>
> Is it possible that you need to treat the file as a binary file?  It's
> rare, but very possible that something like:
>
>     f = open(somefilename,'r')
>     a = f.read()
>
> will give you different results on different platforms, because newline
> translation occurs on the Windows end of things.  ("\n" --> "\r\n" or visa
> versa)  So if your file coincidently has bytes with the sequential values:
>
> ######
> >>> ord('\r'), ord('\n')
> (13, 10)
> ######
>
> then we should expect to see those two bytes collapsed down to a single
> one through the mechanism of newline translation.
>
>
> But if this is happening, there's an easy fix:
>
>     f = open(somefilename,'rb')
>     a = f.read()
>
> where we open the file in binary mode.
>
>
> Good luck!
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20060202/dc4f72cf/attachment.htm 


More information about the Tutor mailing list