Author rhettinger
Recipients docs@python, rhettinger
Date 2018-11-26.18:49:06
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1543258146.71.0.788709270274.issue35318@psf.upfronthosting.co.za>
In-reply-to
Content
The "encoding" parameter is documented to default to sys.getdefaultencoding(). That may be true but there doesn't seem to be a way to use that default because objects will all have a __str__ or __repr__ that will be run instead.

-------------------------------------------
>>> import sys
>>> sys.getdefaultencoding()     # Default encoding is utf-8
'utf-8'
>>> buffer = b'lim x \xe2\x9f\xb6 \xe2\x88\x9e, 1/sin\xc2\xb2(x)'
>>> str(buffer, 'utf-8')         # Explicit argument decodes properly
'lim x ⟶ ∞, 1/sin²(x)'   
>>> str(buffer)                  # Despite the default, repr is shown 
"b'lim x \\xe2\\x9f\\xb6 \\xe2\\x88\\x9e, 1/sin\\xc2\\xb2(x)'"

>>> print(str.__doc__)
str(object='') -> str
str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or
errors is specified, then the object must expose a data buffer
that will be decoded using the given encoding and error handler.
Otherwise, returns the result of object.__str__() (if defined)
or repr(object).
encoding defaults to sys.getdefaultencoding().
errors defaults to 'strict'.
History
Date User Action Args
2018-11-26 18:49:06rhettingersetrecipients: + rhettinger, docs@python
2018-11-26 18:49:06rhettingersetmessageid: <1543258146.71.0.788709270274.issue35318@psf.upfronthosting.co.za>
2018-11-26 18:49:06rhettingerlinkissue35318 messages
2018-11-26 18:49:06rhettingercreate