Search code examples
pythonpython-3.7octal

How can i convert UTF-8 text to octal in Python 3.7?


For example if i had to convert text to hex i can use

    import binascii
    x = input()
    print(str(binascii.b2a_hex(x.encode("utf-8")))[2:-2])

But I cant do that for octal.


Solution

  • It's a great question, my mind went to something like this

    x=[chr(x) for x in range(97,123)]
    y=[oct(ord(i)) for i in x]
    print(dict(zip(x,y)))