How to print a file in binary mode
Luwian at gmail.com
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
fileWrite = open('a.jpg',''ab')
fileRead = open('a.jpg','rb')
b = fileRead.read()
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?
More information about the Python-list