string - Python 2 vs Python 3 straight bytes converting -
i have python 2 code, works alright:
# python 2 key = 'l\x1e@\xael\xc0\xa9\xa3\x8d\x9e5\xac\x00\xe5\x98h' # type(key) => <type 'str'>
originally key random 32bytes value. , here share repr()
values.
so can use random bytes-like sequence string. when comes python3, incoming string in bytes:
# python 3 key = b'l\x1e@\xael\xc0\xa9\xa3\x8d\x9e5\xac\x00\xe5\x98h' # type(key) => <class 'bytes'>
and need convert string "as looks", without replacing characters.
i tried though ascii:
key_chuncks = [chr(s) s in key] # ['l', '\x1e', '@', '®', 'l', 'À', '©', '£', '\x8d', '\x9e', '5', '¬', '\x00', 'å', '\x98', 'h']
as see chr(s)
interpretes bytes sequences characters , don't need behavior. there way, convert bytes string "as looks"? without character interpretation (decoding). ?
all need convert key_before
key_after
in python3
key_before = b'l\x1e@\xael\xc0\xa9\xa3\x8d\x9e5\xac\x00\xe5\x98h' key_after = 'l\x1e@\xael\xc0\xa9\xa3\x8d\x9e5\xac\x00\xe5\x98h' # type(key_after) => <type 'str'>
Comments
Post a Comment