求问大佬,{b'status': b'Starting', b'CreateTime': b'1days', b'FinishedTime': b'2days'} 怎么才能将上面的字典中字节高效的转换成字符串
{'status': 'Starting', 'CreateTime': '1days', 'FinishedTime': '2days'}
1
kunluanbudang 2018-07-26 18:58:23 +08:00
```
In [1]: d1 = {b'status': b'Starting', b'CreateTime': b'1days', b'FinishedTime': b'2days'} In [2]: d1 Out[2]: {b'status': b'Starting', b'CreateTime': b'1days', b'FinishedTime': b'2days'} In [3]: d2 = {k.decode('utf-8'): v.decode('utf-8') for k, v in d1.items()} In [4]: d2 Out[4]: {'status': 'Starting', 'CreateTime': '1days', 'FinishedTime': '2days'} In [5]: ``` like this? |
2
mystar OP @kunluanbudang 实在不行只能这样了,难道 python3 没有相关的 API 吗。。。
|
3
compiler 2018-07-26 23:19:03 +08:00
别去特意追求 Pythonic
|
4
zhzer 2018-07-27 08:50:11 +08:00
高效?写 c 吧
|
5
SoulMelody 2018-07-27 10:58:24 +08:00
import simplejson as json
json.loads(json.dumps({b'status': b'Starting', b'CreateTime': b'1days', b'FinishedTime': b'2days'})) |