将字符串转换为bytes:
str.encode(encoding='UTF-8',errors='strict')
1. encoding -- 使用的编码
- "UTF-8"
- "ASCII"
- "UTF-32"
2. errors -- 设置不同错误的处理方案
- 'strict':UnicodeError
- 'ignore':
- 'replace':
- 'xmlcharrefreplace':
- 'backslashreplace':
- 'codecs.register_error()':
将bytes转换为字符串:
str.decode(encoding='UTF-8',errors='strict')
1. encoding -- 使用的编码
- "UTF-8"
- "ASCII"
- "UTF-32"
2. errors -- 设置不同错误的处理方案
- 'strict':UnicodeError
- 'ignore':
- 'replace':
- 'xmlcharrefreplace':
- 'backslashreplace':
- 'codecs.register_error()':