TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

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

54 点作者 noego超过 5 年前

10 条评论

ryandvm超过 5 年前
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 未加载
LoreleiPenn超过 5 年前
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...
zdw超过 5 年前
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 未加载
pjc50超过 5 年前
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_x超过 5 年前
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 未加载
zitterbewegung超过 5 年前
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 未加载
swalsh超过 5 年前
I literally just got on a phone call to discuss our migration away from 2.7, very timely post.
classified超过 5 年前
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 未加载
mixmastamyk超过 5 年前
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.
grifball超过 5 年前
sed -i &#x27;s&#x2F;print \(&quot;[^&quot;]*&quot;\)&#x2F;print(\1)&#x27;