TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

How to Port from Python 2 to Python 3 (2019)

54 pointsby noegoover 5 years ago

10 comments

ryandvmover 5 years ago
Python 3 and IPv6 are the poster-children of how _not_ to do a major upgrade. I'm not sure what the right way is, but if the short-term advantages of the upgrade do not outweigh the immediate pain, prepare for the matter to drag out for _decades_.
评论 #22127650 未加载
评论 #22128204 未加载
评论 #22127900 未加载
评论 #22127645 未加载
评论 #22130248 未加载
LoreleiPennover 5 years ago
Hopefully no more people will keep saying &quot;learn Python 2 because 3 has almost no packages&quot;.<p>It is so easy for people to just repeat what they heard even if that idea originated a decade ago and was valid a decade ago.<p>And that way we got into a mess of not migrating until pass the time it is no longer supported...
zdwover 5 years ago
I&#x27;ve been doing a lot of Python 2 -&gt; 3 lately, and found this to be one of the best actionable guides: <a href="https:&#x2F;&#x2F;portingguide.readthedocs.io&#x2F;en&#x2F;latest" rel="nofollow">https:&#x2F;&#x2F;portingguide.readthedocs.io&#x2F;en&#x2F;latest</a><p>Also, using tox on the project to run tests against both python 2.7 and multiple versions of 3 and the work goes pretty quickly.
评论 #22129727 未加载
pjc50over 5 years ago
We built a product with an embedded Jython interpreter. Jython is stuck on Python2 and somewhat abandoned. So that&#x27;s nice.<p>Re: packages, one of the huge advantages of the C ecosystem has been that compiled packages are <i>usually</i> fine across language transitions, not only between major compiler version numbers but even from C to C++ which are much more different languages than Python2 to 3. How different would the Python transition have been if it were possible to load Python2 packages in a Python3 program?
o_xover 5 years ago
Isn&#x27;t it ironic that Sentry is one of the tools mentioned in py2-&gt;py3 migration? (Sentry is on py2 and as far as I remember they were not very optimistic about migrating)
评论 #22127694 未加载
zitterbewegungover 5 years ago
The big issue of ports like these is not the tutorial but to justify that to your boss.<p>From enterprise to a self run startup you have to see if it’s worth it .
评论 #22127779 未加载
评论 #22128450 未加载
swalshover 5 years ago
I literally just got on a phone call to discuss our migration away from 2.7, very timely post.
classifiedover 5 years ago
IIRC, the Python used in the macOS vim(1) is still 2.x. So at least on a Mac it won&#x27;t be possible to just move on to Py3 and forget &#x2F; uninstall Py2 for the foreseeable future.
评论 #22127997 未加载
评论 #22128387 未加载
mixmastamykover 5 years ago
Porting is a non-event for most non-large projects. In short:<p>- First cut a new major version<p>- Write a few tests if needed, they go a long way here.<p>- Update to 2.7 best practices and logging<p>- Run tests, commit<p>- Add a few future statements, commit<p>- Run pyflakes3 on it, fix, commit<p>- Run under 3.x&#x2F;fix until clean, commit<p>However, if your project is huge and&#x2F;or does a lot of string and bit twiddling it&#x27;s excruciating. Hence the controversy between factions.
grifballover 5 years ago
sed -i &#x27;s&#x2F;print \(&quot;[^&quot;]*&quot;\)&#x2F;print(\1)&#x27;