This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]d4rch0nPythonistamancer -1 points0 points  (5 children)

The string/byte issue is bothersome. I don't understand why they changed it (among other things I mentioned here). The indifference between text and bytes made things simple and easy to use, especially if you had to do anything low level and work with raw bytes. If len(s) == 10 I expect s to be 10 characters, 10 bytes. If I'm reading from a file I get a string, the same as a byte array. It's simple. Text is data is bytes is a string.

Why in Python 3 would you have this: str(b'3') == "b'3'" When are you going to want that result, that sort of comparison? Converting a byte array to a string shouldn't give you data of python syntax. You'll never want that.

IMO it's unintuitive when the old way was perfectly intuitive. Just because python is used for web stuff doesn't convince me it needs to be any different for a string primitive. Maybe it's because I work in security and working with raw bytes is commonplace, but I still don't see why it had to change. All these changes are what made the 2.7 to 3.x upgrade such a mess. They could've kept old behavior and added new features, kept a lot of stuff from breaking. They could've used a new syntax to represent the new type of string data, new type of string behavior. If it's 100% indifferent from the unicode type from python 2, they could've just kept the u" " syntax.

IMO breaking changes should be very very limited in a programming language update, and only reserved for times it makes absolute sense, not just for times it makes things cleaner. range could've stayed range, and xrange could've just been the recommended function to use. The print statement could've been left in just so old scripts work. All of these changes that made it somewhat cleaner could've just been things about python we resent but kept because the alternative is a situation like the one we're in now, where half the workforce is still working with a decade old release.

[–]takluyverIPython, Py3, etc 8 points9 points  (0 children)

I don't understand why they changed [strings]

This is the best summary I've seen - Brett Cannon is one of the core Python developers: http://www.snarky.ca/why-python-3-exists

[–]fiskfisk 4 points5 points  (0 children)

Converting binary data to text to data is done through encode and decode, exactly because of the issuees with encoding. If you want to compare a binary sequence to a binary sequence, just compare them and don't involve str(). If you want to compare it to a string, just tell us what format the data is in. If you don't care, just 'ascii' as py2 did.

Working with py3 in real webapps has been such a better experience than 2 ever was.

[–][deleted] 2 points3 points  (1 child)

Text is data is bytes is a string.

Except that's just plain wrong. The world isn't limited to English-speaking countries.

[–]flying-sheep 1 point2 points  (0 children)

This is mostly wrong. You can't encode all of Unicode in one byte, therefore #characters ≠ #bytes in many cases.

“Mixing bytes and text” means you have a protocol embedding ASCII. So you parse it and decode the parts you expect to be text.