[ python-Bugs-1450456 ] windows python truncates files when reading them

SourceForge.net noreply at sourceforge.net
Wed Mar 15 16:22:39 CET 2006


Bugs item #1450456, was opened at 2006-03-15 15:17
Message generated for change (Comment added) made by gbrandl
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1450456&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Windows
Group: Python 2.4
>Status: Pending
>Resolution: Invalid
Priority: 5
Submitted By: tom berger (object)
Assigned to: Nobody/Anonymous (nobody)
Summary: windows python truncates files when reading them

Initial Comment:
when using python for windows, opening a file and
calling read() on the file object returns only some of
the file (about 1K). i am expecting read to return the
entire contents of the file (and this is what i get
when i run the same code on cygwin and linux).

to reproduce:

prepare a sufficiently large file myfile.xxx (say > 100K)

source = open('myfile.xxx', 'r')
dest = open('copy_myfile.xxx', 'w')
dest.write(source.read())
source.close()
dest.close()

myfile.xxx and copy_myfile.xxx should be identical, and
they are if you run this on most python distributions.
when running the version installed from the .msi
installer on python.org the copy is truncated (as part
of reading, i'm pretty sure).

----------------------------------------------------------------------

>Comment By: Georg Brandl (gbrandl)
Date: 2006-03-15 15:22

Message:
Logged In: YES 
user_id=849994

I'm guessing here, but the only conclusion is that you are
reading a binary file. Since Windows makes a difference
between text and binary files, you must read the file with
mode 'rb', or Windows will stop at the first chr(26) ==
Ctrl+Z == EOF.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1450456&group_id=5470


More information about the Python-bugs-list mailing list