相关疑难解决方法(0)

在Python 3中将字符串转换为字节的最佳方法?

似乎有两种不同的方法将字符串转换为字节,如TypeError的答案所示:'str'不支持缓冲区接口

哪种方法更好或更好Pythonic?或者只是个人喜好?

b = bytes(mystring, 'utf-8')

b = mystring.encode('utf-8')
Run Code Online (Sandbox Code Playgroud)

python string character-encoding python-3.x

734
推荐指数
5
解决办法
110万
查看次数

标签 统计

character-encoding ×1

python ×1

python-3.x ×1

string ×1