I got below info from other device:
foo = { "abc": "b'E3:DE'" }
I know "b" prefix means byte in Python 3. My intent is to convert it into a string. My Python version treats it as unicode
type. I tried many ways, none work. The prefix "b" is always there and it is even considered as a character which can be uppercased.
foo = xxx.get("abc")
logger.info("1 foo type {0} against {1} isinstance(foo, unicode) {2}".format(type(foo), type(b''), isinstance(foo, unicode)))
logger.info("2 before anything {0}".format(foo))
foo1 = foo.encode("utf-8")
logger.info("3 after encode foo1 {0} type {1} upper {2}".format(foo1, type(foo1), foo1.upper()))
bar = foo.decode("utf-8")
logger.info("4 after decode bar {0} type {1} upper {2}".format(bar, type(bar), bar.upper()))
Output:
INFO|1 foo type <type 'unicode'> against <type 'str'> isinstance(foo, unicode) True
INFO|2 before anything b'E3:DE'
INFO|3 after encode foo b'E3:DE' type <type 'str'> upper B'E3:DE'
INFO|4 after decode foo b'E3:DE' type <type 'unicode'> upper B'E3:DE'
Do we have a built-in function to convert this unicode
with "b" prefix into a string without "b" prefix? Or do I have to use substring to get rid of it?