似乎有两种不同的方法将字符串转换为字节,如TypeError的答案所示:'str'不支持缓冲区接口
哪种方法更好或更好Pythonic?或者只是个人喜好?
b = bytes(mystring, 'utf-8') b = mystring.encode('utf-8')
python string character-encoding python-3.x
character-encoding ×1
python ×1
python-3.x ×1
string ×1