Print python os.urandom output on terminal

how can i print the output of os.urandom(n) in terminal?

I try to generate a SECRET_KEY with fabfile and will output the 24 bytes.

Example how i implement both variants in the python shell:

>>> import os
>>> out = os.urandom(24)
>>> out
>>> print out

Best answer

If what you want is hex-encoded string, use binascii.a2b_hex (or hexlify):

>>> out = 'oS\xf8\xf4\xe2\xc8\xda\xe3\x7f\xc75*\x83\xb1\x06\x8c\x85\xa4\xa7piE\xd6I'
>>> import binascii
>>> print binascii.hexlify(out)