How to print a file in binary mode

Fredrik Lundh fredrik at pythonware.com
Sun Oct 22 12:21:15 EDT 2006


Lucas wrote:

> well,  if I just open the file in binary mode, and write a string,e.g
> '660', how do i read the result? I means I need print the binary in
> screen.

I'm afraid that the more you write, the less sense you make.

> do these?
> 
> fileWrite = open('a.jpg','ab')
> fileWrite.write('660')
> fileWrite.close()
> 
> fileRead = open('a.jpg','rb')
> b = fileRead.read()
> fileRead.close()
> print b

that prints three bytes, "6", "6", and "0":

 >>> fileWrite = open('a.jpg','ab')
 >>> fileWrite.write('660')
 >>> fileWrite.close()

 >>> fileRead = open('a.jpg','rb')
 >>> b = fileRead.read()
 >>> fileRead.close()
 >>> print b
660

what do you want it to print ?

</F>




More information about the Python-list mailing list