Returns a regular string containing a copy of the original string, encoded using the codec registered for the specified encoding.
Since Python 2.7: You can also specify the arguments to this method as keyword arguments, for clarity.
- encoding
- Optional. The encoding you wish to encode the string to. If not specified, the value from sys.getdefaultencoding is used.
- errors
- Optional. The error handling scheme to use. Can be any of the following values, or any other name that is registered through codecs.register_error.
- strict
- This is the default. Encoding errors raise a UnicodeError exception, or a subclass thereof.
- ignore
- When an error is encountered, ignore the character, and move on to the next one.
- replace
- When an error is encountered, replace the problematic character with U+FFFD, for the built-in Unicode codecs.
- xmlcharrefreplace
- When an error is encountered, replace the problematic character with the corresponding XML entity.
- backslashreplace
- When an error is encountered, replace the problematic character with the corresponding backslashed escape sequence.