且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

什么是变量上的 b'string' 的等价物?

更新时间:2022-06-25 03:48:21

好吧,您必须决定使用哪种编码.您可以使用 UTF-8 作为合理的默认值,也可以从环境中推断编码.

Well, you have to decide which encoding to use. You can either go with UTF-8 as a sensible default, or infer the encoding from the environment.

环境可以是,例如:

然后您可以通过 var.encode(encoding).

You can then transform your Unicode variable into a bytes string via var.encode(encoding).

另请查看Python Unicode HOWTO.