python打印数据显示为b“xxx“格式,使用data.decode()可以输出“xxx“格式
测试例子
#test.py
str = input()
print(str)
#bash
$python3 test.py
#输入内容
$"输入内容"
$b'输入内容'
使用data.decode()之后
#test.py
str = input()
print(str.decode())
#bash
$python3 test.py
#输入内容
$"输入内容"
$输入内容
bytes是python 3.x新增的类型,在python 2.x中是不存在的。需要对str进行解码以获得一个不带b’'的字符串。
只需使用print(data.decode())来获得正确的输出。如果不指定任何编码,默认行为是使用utf8。说明文档在这个链接pythondoc