Writing binary files in windows

Corey Richardson kb1pkl at aim.com
Sat Feb 12 04:35:23 CET 2011


On 02/11/2011 10:20 PM, Abhishek Gulyani wrote:
> When I write binary files in windows:
> 
> file  = open(r'D:\Data.bin','wb')
> file.write('Random text')
> file.close()
> 
> and then open the file it just shows up as normal text. There is nothing
> binary about it. Why is that?
> 
> Sorry if this is too much of a noobie question. I tried googling around but
> couldn't find an answer.
> 

It is binary! What are you expecting? You wrote text to a file, so when
you open the file with whatever, it displays like text. Even when you
don't open a file as binary, it is still a binary file. Otherwise it
wouldn't exist.



More information about the Python-list mailing list