How to print a file in binary mode

Lucas Luwian at
Sun Oct 22 12:09:54 EDT 2006

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

do these?

fileWrite = open('a.jpg',''ab')

fileRead = open('a.jpg','rb')
b =
print b


Thanks again

Fredrik Lundh wrote:
> Lucas wrote:
> > I do it because I want to encrypt a string into a picture using RSA
> > algorithm.
> what does "into" mean?  are you supposed to encrypt the binary data
> representing the JPEG image, or embed a message into the actual image?
>  > so I first convert the string to binary,and then saving the binary
>  > into picture
> you seem to have a rather fuzzy understanding of the words "string" and
> "binary" here.  if you read from a file that's opened in binary mode,
> you get an 8-bit string that contains the binary data.  there's no need
> for any conversion here; just use the data you got from "read".
>  > finally, print the picture by binary!
> do you mean "save the picture to a binary file", or something else?
> </F>

More information about the Python-list mailing list