Eduard Florinescu Eduard Florinescu - 2 years ago 136
Python Question

Print a string as hex bytes?

I have this string:

Hello world !!
and I want to print it using Python as

works only for integers.

How can it be done?

Answer Source

Your can transform your string to a int generator, apply hex formatting for each element and intercalate with separator:

>>> s = "Hello world !!"
>>> ":".join("{:02x}".format(ord(c)) for c in s)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download