str.join()
only places the joiner between the joined elements. From the str.join()
documentation:
The separator between elements is the string providing this method.
(Bold emphasis mine).
Join on a space instead, and change the format to include the 0x
prefix:
' '.join('{:#04x}'.format(x) for x in exampleArray)
The #
changes the format to include the 0x
prefix for you; do take into account that you need to adjust the field width to take the extra 2 characters into account (each field now takes up 4 characters, including the 0x
prefix).
Demo:
>>> exampleArray = bytearray([0xc0, 0xff, 0x01])
>>> print ' '.join('{:#04x}'.format(x) for x in exampleArray)
0xc0 0xff 0x01