更新时间: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.
环境可以是,例如:
sys.getfilesystemencoding()
函数然后您可以通过 var.encode(encoding)
.
You can then transform your Unicode variable into a bytes string via var.encode(encoding)
.
另请查看Python Unicode HOWTO.