pythonpython-2.7encodingdecodingchardet

How to decode unknown encoded string in python, tried chardet?


I don't know encoding type of string and I want to decode that string. I have tried chardet python module but didn't work.

I know output of string, is there anyway i can decode string using python...

Example

Input
'\x06@\t\xa6'

Output
104860070

Any help would be appreciated


Solution

  • It is text created with struct.pack() so use struct.unpack()

    import struct
    
    result = struct.unpack('!i', '\x06@\t\xa6')[0]
    print(result) 
    
    # 104860070