如何为 Python 3 做好准备?
目前编写能够干净地通过 2to3 的 python 代码的规则是什么?这些实践似乎最适合编写不会永远陷入版本 2 中的代码。
我从 SciPy/NumPy 论坛上读到,“100% 测试覆盖率”(单元测试)对很多人来说都很重要,我也认为不确定这是否适用于所有人。当然,在转换后进行一组合理的单元测试来尝试您的代码似乎是一个明智的步骤。
还有其他事情吗?如果熟练的 Pythonista 正在编写他们希望在 2to3 过程中“干净”地完成的 2.x 代码,他们会做什么。
我正在寻找“[不]这样做”的具体实例以及一些更一般的“最佳实践”,但“该做和不该做”的具体实例很有帮助。
假设框架、库(Django、SciPy/NumPy)和我们需要的所有其他 C 扩展最终都移植到 Python3,我问的是您如何编写和维护您自己编写的纯 Python 语言代码。
更新:我真正想要的是“风格指南”和每个人都已经远离的已弃用功能列表。我在 Python 1.5 上开始学习,然后转向 2.0,然后并没有真正遵循 2.5/2.6 时代的大部分内容,使用它们,但实际上我的代码更多是 2.1 时代的。
What are the current rules for writing python code that will pass cleanly through 2to3 and what are the practices that seem to be best suited to writing code that will not become mired forever in version 2.
I have read from the SciPy/NumPy forums that "100% test coverage" (unit testing) is important for many people, and I am not sure if that would apply to everybody. Certainly having a reasonable set of unit tests to try your code out with after conversion, seems a sane step.
Are there other things? What are skilled Pythonistas doing if they are writing 2.x code that they hope to have come through "cleanly" in the 2to3 process.
I am looking for specific instances of "[don't] do this" as well as some more general "best-practices", but specific instances of "do's and don'ts" are helpful.
Let's assume that frameworks, libraries (Django, SciPy/NumPy), and every other C Extension we need gets ported to Python3 eventually, and I'm asking about how you write and maintain the pure python language code that you write yourself.
Update: It's possible that what I really want is the "style guide" and list of deprecated features that everybody was already staying away from. I cut my teeth on Python 1.5 and moved to 2.0, and then have not really followed much of the 2.5/2.6 era, used them but really my code is more 2.1 era.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会说:
-3
标志运行代码。它会告诉您代码中需要更改的内容。I'd say:
-3
flag. It will tell you about things in your code that will need changing.