[Tutor] Writing BINARY-CONTENT

Stefan Dieck dieck.s at dsoftware.de
Fri Nov 21 09:47:29 EST 2003


Hi!

I have a big problem:

How can I write a (binary) File from Python,
without extending every "\n" to "\n\r"
(I know it's a Windows-Specific Problem)

** Python itself shows written 1 byte, but it writes 2 bytes if a newline
occurs **

* Do you have any Ideas?
* Or, is there a class which writes only these data I submitted?

#################################################################
a = open('c:\\test.me', 'wb')   # opens a file for binary writing
for x in range(256):            #
  a.write(chr(x))               # This should write 256 bytes (from '\x00'
to '\xFF')
a.close()
#################################################################
But the file has a lenght of 257        ( + '\r')



Many Thanks,

Stefan




More information about the Tutor mailing list