|
|
Log in / Subscribe / Register

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

> Every time that you open a file in text mode in Python 3, you are being helped by the new system - which enables Python to read those files in "universal text mode" while applying a text encoding at the same time.

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!


to post comments

2to3?

Posted Jun 2, 2025 10:23 UTC (Mon) by intelfx (subscriber, #130118) [Link] (1 responses)

> Sigh. Now it's clear that people like you are the result of this string disaster.

Whatever point you were trying to make, I'm sure it would have been better off *without* this personal attack.

2to3?

Posted Jun 2, 2025 12:51 UTC (Mon) by Wol (subscriber, #4433) [Link]

I can understand Cyberax' frustration ...

To clarify his point (and yes it took me a while to get it)

"why do other people think it's perfectly okay to trash my data when I haven't told them to!".

File opens should NOT DEFAULT to "assume the contents are mutable and can be altered by the computer without warning". It's a disaster in waiting ...

Still, it goes back as far as ftp, so that's a long way - I can still remember trying to recover the contents of a binary data file that had been transferred in text mode ... and even if it is text, I can remember trying to get printers to work because some stupid system thought it would treat it according to the system convention not the printer definition ...

Cheers,
Wol


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds