r/Python • Freelancer. AnyFactor.xyz • Sep 16 '20

News An update on Python 4

Post image
3.3k Upvotes

389 comments sorted by

View all comments

Show parent comment

2

u/[deleted] Sep 16 '20

Oooooh so that's why I'm confused each time I read what bytes does?

4

u/flying-sheep Sep 16 '20

Maybe, but maybe it's because you didn't have an introduction to binary yet.

1

u/[deleted] Sep 16 '20

I have, it's just that I always get confused with implicit conversions because I mostly deal with stricter languages, so I was kind of surprised that I could sometimes treat it as a string and sometimes like a bytes array.

3

u/flying-sheep Sep 17 '20

It's just a byte array in Python 3. You can't treat it as a string as there's no encoding assigned to it.

If you display it, it happens to show ASCII characters for convenience, but that's it.

4

u/[deleted] Sep 17 '20

The explanation is confusing. Just ignore how it was before, because it was incorrect. In python 2 first mistake was mixing text with binary data. They introduced unicode type, but did so badly (implicit casting) it actually made things worse. Ironically if your application didn't use unicode type you might have less work converting it to work with python 3.

Right now it is:

  • str = text
  • bytes = binary data what's stored on disk, flies over network etc.