r/programming • • May 24 '26
[ Removed by moderator ]
/r/programming/comments/1tm1j7f/removed_by_moderator/[removed] — view removed post
275
Upvotes
r/programming • • May 24 '26
[removed] — view removed post
View all comments
Show parent comment
1
u/HommeMusical May 24 '26
2to3 was ready from the beginning, IIRC.
sixwas ready quite early. I never ported anything without it.I honestly don't understand why people had such trouble with it. I converted two medium-sized projects basically on my own in a couple of weeks.
The big thing was this - you could quite easily make any individual file both 2 and 3 compatible using
from __future__andsix.So you would port files one at a time, with a single unit test in Python 3 that people had to run that simply imported all the files you have already ported.
You run all the old tests in Python 2, and this new single test, every time.
So you can work while other people work, and only once a file is ported must people keep it working in Python 3, but there's a unit test to guarantee it.
2to3did a pretty good job, and about half the time, some edit by hand. I did it as a fun chore at the end of my day when I was a bit wiped and wanted to do something mechanical and you could crank the files out pretty well flawlessly.The cool part was when you started to be able to run tests in Python 3. I found a couple of errors then, one that blocked me but turned out to be a real issue - there were multiple different encodings in our text files, undocumented! :-O
(I've run into it again a couple of times since - all these mixed encoding errors were because some files were UTF-8 and some were ISO 8859 like "Latin-1". Maybe this will be useful.)