SOLVED: Write \x1a to binary file

Harald Schneider h_schneider at marketmix.com
Tue Jul 16 13:07:56 EDT 2002


Thanks a lot!

I was a little bit fast with my request. Due to a bug, the end of my file
was overwritten, so that the end marker \x1a was deleted.
In fact, it is sufficient to open the file with mode 'b' to write all kind
of binary data (on Win32, running Active Python 2.1).

BUT:
One strange side effect, I recogniced ...
- I write \x1a to the end of a file.
- I close it and reopen in text mode
 The result: the last byte gets cut off ... even when nothing is written to
that file!

All the best,
Harald



"Fredrik Lundh" <fredrik at pythonware.com> schrieb im Newsbeitrag
news:U6FY8.47572$n4.11655517 at newsc.telia.net...
> Martin v. Loewis wrote:
>
> > > I've got a problem with writing "\x1A" to a binary file on Win32
platform.
> > > I think due tue an issue wiht popen() this terminates the output
stream. Is
> > > there any solution for this ?
> >
> > I think there is some win32 module that allows you to set the default
> > open mode for files to "binary".
>
> msvcrt.setmode(filehandle, mode)
>
> see http://www.python.org/doc/current/lib/msvcrt-files.html
> for a bit more information.
>
> </F>
>
>









More information about the Python-list mailing list