How to print a file in binary mode
Luwian at gmail.com
Sun Oct 22 15:33:50 CEST 2006
thanks for your answer.
I known how to do it.
read() return a string. so
1) bytes = read(1) #read the file by bit.
2) chrString = ord(bytes) #convert the string to ASCII.
3) print numberToBinary(chrString) #convert the ASCII to Binary using
I do it because I want to encrypt a string into a picture using RSA
so I first convert the string to binary,and then saving the binary into
finally, print the picture by binary!
It is my coursework and studying PYTHON passingly : )
Marc 'BlackJack' Rintsch wrote:
> In <1161519385.614985.311240 at m73g2000cwd.googlegroups.com>, Lucas wrote:
> > I need print a file in binary mode .
> > f = f.open('python.jpg','rb')
> > bytes = f.read()
> > f.close()
> > print(bytes)
> > I can't get any binary code.
> What do you mean by "binary code"? If you use ``print repr(bytes)``
> everything outside ASCII will be printed as escape sequence.
> But why do you want to "print" JPEG images anyway?
> Marc 'BlackJack' Rintsch
More information about the Python-list