Thanks Danny!

that solved it.

Johan

On 2/2/06, Danny Yoo <[EMAIL PROTECTED]> 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!


_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to