哪些 PEP 是必读的?

发布于 2024-08-03 20:50:59 字数 110 浏览 7 评论 0原文

我是一名相当强大的 Python 编码员,但我的风格太多有点随意,而且我确信对于许多问题,比我想出的解决方案有更多的 Pythonic 解决方案。哪些 PEP 对于精通 Python 的人来说是必不可少的?

I'm a fairly strong Python coder, but too much of my style is a little haphazard, and I'm sure there are more Pythonic solutions to many problems than the ones I come up with. Which PEPs are essential for any well versed Pythonista to read?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

来日方长 2024-08-10 20:50:59

绝对是 PEP 8,Python 风格指南。

Definitely PEP 8, a Style Guide for Python.

撩人痒 2024-08-10 20:50:59

尽管Python非常直观,但很多人并不理解他的哲学。

Pep 20Python 之禅

  • 美丽总比丑陋好。
  • 显式优于隐式。
  • 简单胜于复杂。
  • 复杂总比复杂好。
  • 扁平比嵌套更好。
  • 稀疏优于密集。
  • 可读性很重要。
  • 特殊情况还不足以违反规则。
  • 尽管实用性胜过纯粹性。
  • 错误永远不应该悄无声息地过去。
  • 除非明确禁止。
  • 面对歧义,拒绝猜测的诱惑。
  • 应该有一种——最好只有一种——明显的方法来做到这一点
    它。
  • 虽然这种方式一开始可能并不明显,除非您是荷兰人。
  • 现在总比没有好。
  • 虽然永远都比现在更好。
  • 如果实现很难解释,那就不是一个好主意。
  • 如果实现很容易解释,这可能是个好主意。
  • 命名空间是一个非常棒的想法 - 让我们做更多这样的事情!

Although Python is incredibly intuitive, a lot of people do not comprehend his philosophy.

Pep 20: The Zen of Python

  • Beautiful is better than ugly.
  • Explicit is better than implicit.
  • Simple is better than complex.
  • Complex is better than complicated.
  • Flat is better than nested.
  • Sparse is better than dense.
  • Readability counts.
  • Special cases aren't special enough to break the rules.
  • Although practicality beats purity.
  • Errors should never pass silently.
  • Unless explicitly silenced.
  • In the face of ambiguity, refuse the temptation to guess.
  • There should be one-- and preferably only one --obvious way to do
    it.
  • Although that way may not be obvious at first unless you're Dutch.
  • Now is better than never.
  • Although never is often better than right now.
  • If the implementation is hard to explain, it's a bad idea.
  • If the implementation is easy to explain, it may be a good idea.
  • Namespaces are one honking great idea -- let's do more of those!
踏月而来 2024-08-10 20:50:59

It is now retrospective, but still interesting: I think Things that will Not Change in Python 3000 is a good read, with lots of links to the discussions that preceded the decisions.

酒绊 2024-08-10 20:50:59

另外 pep 0257 文档字符串约定

Also pep 0257 docstring convention

心碎无痕… 2024-08-10 20:50:59

我发现阅读那些被拒绝的文章可以让我们深入了解什么是Pythonic、什么不是。
这是不久前的事了,所以我没有任何具体的例子。

I found that reading the declined ones can give some good insights into what's Pythonic and what isn't.
This was a while ago so I don't have any specific examples.

静若繁花 2024-08-10 20:50:59

我还推荐 PEP 8 和 257。我知道这与最初的问题略有不同,但我想指出 PyCharm(在我看来可能是最好的 Python IDE)会自动检查您是否遵循了一些最重要的 PEP 8 指南,以防万一有人感兴趣......

I'd also recommend PEPs 8 and 257. I know this deviates slightly from the original question, but I'd like to point out that PyCharm (probably the best Python IDE around in my opinion) automatically checks if you're following some of the most important PEP 8 guidelines, just in case anyone's interested...

棒棒糖 2024-08-10 20:50:59

这是 PEP 的索引 - http://www.python.org/dev/peps/

当有人对某个主题有疑问时,他们可以在该主题中进行搜索

Here is a index of PEP - http://www.python.org/dev/peps/

when ever one has doubt about a topic, they can search in that

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文