Reputation: 16264
The Python documentation on str.decode and encode allow an "error handling scheme". What does the replace
option mean or do?
Upvotes: 0
Views: 58
Reputation: 249384
If you follow the link in the doc you referenced, it goes here: https://docs.python.org/2/library/codecs.html#codec-base-classes
Which says replace
does this:
Replace with a suitable replacement character; Python will use the official U+FFFD REPLACEMENT CHARACTER for the built-in Unicode codecs on decoding and ‘?’ on encoding.
U+FFFD is:
Used to replace an incoming character whose value is unknown or unrepresentable in Unicode.
So basically the replace
option puts a "dummy" character in the output wherever the input had a "bad" character that could not be decoded or encoded.
Upvotes: 1