On Wed, May 16, 2018 at 9:02 AM, Skip Montanaro
wrote:
>> Personally, I never use the str(..., encoding="...") notation; I prefer
> to use the
>> .decode() method of the bytes object.
>
> Thanks. And thanks for the other responses. I obviously didn't have my
> thinking
> Personally, I never use the str(..., encoding="...") notation; I prefer
to use the
> .decode() method of the bytes object.
Thanks. And thanks for the other responses. I obviously didn't have my
thinking cap on this morning. (It was too late in the morning to plead lack
of coffee.)
Skip
--
On Wed, May 16, 2018 at 1:14 AM, Skip Montanaro
wrote:
> Consider this:
>
bytes("abc", encoding="utf-8")
> b'abc'
>
> Looks reasonable. Then consider this:
>
str(bytes("abc", encoding="utf-8"))
> "b'abc'"
>
> Why is the b'...' bit still there? I suppose it's
15.05.18 18:14, Skip Montanaro пише:
Consider this:
bytes("abc", encoding="utf-8")
b'abc'
Looks reasonable. Then consider this:
str(bytes("abc", encoding="utf-8"))
"b'abc'"
Why is the b'...' bit still there? I suppose it's because I didn't tell it
explicitly how to decode the bytes
Skip Montanaro writes:
> Consider this:
>
> >>> bytes("abc", encoding="utf-8")
> b'abc'
>
> Looks reasonable. Then consider this:
>
> >>> str(bytes("abc", encoding="utf-8"))
> "b'abc'"
>
> Why is the b'...' bit still there?
Because the bytes object is asked for a text
On 05/15/2018 08:14 AM, Skip Montanaro wrote:
Consider this:
bytes("abc", encoding="utf-8")
b'abc'
Looks reasonable. Then consider this:
str(bytes("abc", encoding="utf-8"))
"b'abc'"
Why is the b'...' bit still there?
Because you are printing a bytes object, not a str.
I suppose it's
Consider this:
>>> bytes("abc", encoding="utf-8")
b'abc'
Looks reasonable. Then consider this:
>>> str(bytes("abc", encoding="utf-8"))
"b'abc'"
Why is the b'...' bit still there? I suppose it's because I didn't tell it
explicitly how to decode the bytes object, as when I do, I get the expected