2to3?
2to3?
Posted Jun 2, 2025 2:32 UTC (Mon) by Cyberax (✭ supporter ✭, #52523)In reply to: 2to3? by zahlman
Parent article: Recent disruptive changes from Setuptools
Thanks for reminding me. Yes, I sometimes forget to add the binary mode and this often bites me later when Python inanely converts files.
Bonus point if the computer where it's deployed has an ISO encoding, and not UTF-8.
> Every time you specify the wrong encoding when opening a file, Python 3 helps you by forcing you to attempt the decoding at the correct point in your program - thus reporting the error at the time you read from the file, instead of arbitrarily far into the rest of your code.
Or not reporting, and just silently corrupting the data.
> Since Python 3.3 (see https://peps.python.org/pep-0393/), every time you use len() on a string that includes characters outside the BMP, Python 3 helps you by always correctly counting the characters you put into the string
Sigh. Now it's clear that people like you are the result of this string disaster. You never once stopped to ask: "WHAT is the length of string?"
Is it the number of characters? The number of code points? The number of graphemes? What exactly do you mean by it? Why do you even _want_ to know the length of a string?
Py3 string length does not even uphold this equality: "len(string) = len(split1) + len(split2)" for all arbitrary strings split on the "character" boundary!
