gpt4 book ai didi

python - 注释行超过 79 个字符

转载 作者:行者123 更新时间:2023-12-01 01:47:20 24 4
gpt4 key购买 nike

当我有例如这一行:full_path = "https://www.google.cz/search?q="+ website_keywords # 谷歌链接网址
Flake8 报告我,队列中的字符数最多超过 79 个。长度。当 PEP 8 规定内联注释应该与特定语句位于同一行时,我应该如何处理注释。

最佳答案

通常可以在行上方添加这样的注释:

# google link url
full_path = "https://www.google.cz/search?q=" + website_keywords

顺便说一句,截至撰写本文时,PEP 8 表示评论的行数限制仅为 72 行。

For flowing long blocks of text with fewer structural restrictions (docstrings or comments), the line length should be limited to 72 characters.

...

Some teams strongly prefer a longer line length. For code maintained exclusively or primarily by a team that can reach agreement on this issue, it is okay to increase the nominal line length from 80 to 100 characters (effectively increasing the maximum length to 99 characters), provided that comments and docstrings are still wrapped at 72 characters.

尚不清楚这是否适用于内联注释,因为它们不是“长文本 block ”,但 PEP 8 还表示,

Inline comments are unnecessary and in fact distracting if they state the obvious.

您可以考虑完全删除该评论。考虑到字符串中包含“google”,它是 Google URL 的事实很明显。


有一种情况,评论确实必须与它所评论的内容在同一行 - PEP-484 type comments 。在这种情况下,您可以使用括号:

full_path = (
"https://www.google.cz/search?q=" + website_keywords
) # type: str

关于python - 注释行超过 79 个字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51147228/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com