Le Wed, 28 Apr 2010 23:54:07 +0200, Dodo a écrit : > Help! this is driving me crazy lol > I want to print raw binary data to display an image file BUT > python3 outputs b'<binary data>' instead of <binary data>.... so the > browser can't read the image!! > > f = open("/some/path/%s" % x, 'rb') > print(f.read())
print() implicitly converts its arguments to str (i.e. unicode strings) and then writes them to sys.stdout, which is a text IO wrapper. If you want to bypass the unicode layer, you have to use sys.stdout.buffer instead. That is: sys.stdout.buffer.write(f.read()) Regards Antoine. -- http://mail.python.org/mailman/listinfo/python-list