文章内容

2021/3/26 19:55:12,作 者: 黄兵

Python 将bytes数据转换成string数据

最近在数据库查询得到的数据时bytes,但是通过第三方API调用需要的时string数据类型,需要对数据类型进行转换。

在Python中将bytes数据类型转换成string类型,具体代码如下:

>>> b"abcde"
b'abcde'

# utf-8 is used here because it is a very common encoding, but you
# need to use the encoding your data is actually in.
>>> b"abcde".decode("utf-8") 
'abcde'


参考资料:

1、Convert bytes to a string

分享到:

发表评论

评论列表