Re: What's the rationale for b"..." in this example?

2018-05-15 Thread Chris Angelico
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

Re: What's the rationale for b"..." in this example?

2018-05-15 Thread Skip Montanaro
> 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 --

Re: What's the rationale for b"..." in this example?

2018-05-15 Thread Chris Angelico
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

Re: What's the rationale for b"..." in this example?

2018-05-15 Thread Serhiy Storchaka
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

Re: What's the rationale for b"..." in this example?

2018-05-15 Thread Ben Finney
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

Re: What's the rationale for b"..." in this example?

2018-05-15 Thread Ethan Furman
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

What's the rationale for b"..." in this example?

2018-05-15 Thread 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 object, as when I do, I get the expected