#!/usr/bin/env python
# -*- coding: utf-8 -*-
import struct
for current_byte in list(open('example.txt','rb').read()):
    print hex(struct.unpack("B",current_byte)[0]),
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import struct, os
filename = 'example.txt'
byte_list = list(open(filename,'rb').read())
for key in range(0, os.path.getsize(filename)):
    print hex(struct.unpack("B", byte_list[key])[0]).ljust(4,' '),
    print "\n" if (key+1)%10 == 0 else "",
Format output.