msg258583 - (view) |
Author: Johnny Wezel (jwezel) |
Date: 2016-01-19 11:52 |
str(b'xxx') returns "b'xxx'" instead of 'xxx' |
|
|
msg258588 - (view) |
Author: STINNER Victor (vstinner) *  |
Date: 2016-01-19 12:33 |
Yes. It's a feature, not a bug. You muse decode manually bytes to get type: b'xxx'.decode('ascii') or str(b'xxx'.decode('ascii')). |
|
|
msg258589 - (view) |
Author: Johnny Wezel (jwezel) |
Date: 2016-01-19 12:42 |
Bad feature, as it is a violation of POLA. |
|
|
msg258603 - (view) |
Author: Eryk Sun (eryksun) *  |
Date: 2016-01-19 16:02 |
> Bad feature, as it is a violation of POLA. I would be astonished if the default __str__ conversion returned a Latin-1 decoding, which won't fail, or used the locale encoding or UTF-8, which could fail. The more explicit call x.decode() uses UTF-8 as the default encoding. |
|
|
msg258604 - (view) |
Author: Johnny Wezel (jwezel) |
Date: 2016-01-19 16:06 |
Who's talking about latin-1 in Python3? Of course str() needs to return decode('utf-8'). |
|
|
msg258606 - (view) |
Author: Walter Dörwald (doerwalter) *  |
Date: 2016-01-19 16:14 |
> Who's talking about latin-1 in Python3? Of course str() needs to return decode('utf-8'). So that would mean that: print(b"\xff") will always fail! |
|
|
msg258608 - (view) |
Author: Johnny Wezel (jwezel) |
Date: 2016-01-19 16:19 |
The other question is why one would want to run such a statement. This is almost certainly a bug in which case an error one would be better off with an exception. |
|
|
msg258610 - (view) |
Author: Walter Dörwald (doerwalter) *  |
Date: 2016-01-19 17:15 |
But this leads to uninspectable objects. |
|
|
msg258620 - (view) |
Author: Martin Panter (martin.panter) *  |
Date: 2016-01-19 20:46 |
A warning is already emitted if you enable it with the “-b” flag, which I recommend. You can even turn the warning into an error with “-bb”. And you can always use repr() or ascii() to inspect for a more robust inspection. $ python3 -bb Python 3.5.0 (default, Sep 20 2015, 11:28:25) [GCC 5.2.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> print(b"\xFF") Traceback (most recent call last): File "", line 1, in BytesWarning: str() on a bytes instance >>> print(repr(b"\xFF")) b'\xff' |
|
|
msg258625 - (view) |
Author: Johnny Wezel (jwezel) |
Date: 2016-01-19 21:58 |
> But this leads to uninspectable objects. An inspection would be done with repr() which should not cause a problem. Besides. the official and correct way of handling an ff character is to emit a Unicode replacement code, not to issue an exception. Another flaw in the whole story. |
|
|