在块注释中,我想引用一个长度超过80个字符的 URL。
显示此 URL 的首选常规是什么?
我知道 bit. ly 是一个选项, 但 URL 本身是描述性的。 缩短它, 然后用嵌套的评论描述缩短的 URL 似乎是一个错误的解决方案 。
在块注释中,我想引用一个长度超过80个字符的 URL。
显示此 URL 的首选常规是什么?
我知道 bit. ly 是一个选项, 但 URL 本身是描述性的。 缩短它, 然后用嵌套的评论描述缩短的 URL 似乎是一个错误的解决方案 。
不要打破url:
忽略某项准则的其他一些良好理由:
- When applying the guideline would make the code less readable, even for someone who is used to reading code that follows this PEP. ...
资料来源:
# A Foolish Consistency is the Hobgoblin of Little Minds [1]
# [1]: http://www.python.org/dev/peps/pep-0008/#a-foolish-consistency-is-the-hobgoblin-of-little-minds
You can use the # noqa at the end of the line to stop PEP8/pycodestyle/Flake8 from running that check. Should also avoid warnings in your IDE.
# [1]: http://www.python.org/dev/peps/pep-0008/#a-foolish-consistency-is-the-hobgoblin-of-little-minds # noqa
来自PEP8
但最重要的是:知道何时前后不一 -- 有时风格指南就是不适用。 当有疑问时, 请使用你最好的判断。 看看其他例子, 并决定什么是最好的。 并且不要犹豫询问!
违反特定规则的两个良好理由:
- When applying the rule would make the code less readable, even for someone who is used to reading code that follows the rules.
就我个人而言,我会使用这个建议, 而不是在您的评论中 留下完整的描述性 URL 给人们。
您可以在行末使用 来阻止 PEP8/Flake8 执行检查。 PEP8允许通过 :
特殊情况并不特别,无法打破规则。
如果您使用flache8:
"""
long-url: http://stackoverflow.com/questions/10739843/how-should-i-format-a-long-url-in-a-python-comment-and-still-be-pep8-compliant
""" # noqa
将# noqa 添加到全部的笔记本工作上, 但这意味着您会失去对整个笔记本工作的反省, 这样您就可以忽略其它问题 。
若您想将您的 noqa 缩小到仅长线, 您只能将其添加到长线, 但# noqa 在用 sphinx 构建时出现在文档中 。
在此情况下, 您可以建立自定义的自定义自动博士处理方法 。 < a href="https:// stackoverflow.com/ questions/ 26534184/can- sphinx- ignore- certain- tags- in- python- docstrings" > 这个答案 。
这是我改编的版本
from sphinx.application import Sphinx
import re
def setup(app):
noqa_regex = re.compile( ^(.*)ss#snoqa.*$ )
def trim_noqa(app, what_, name, obj, options):
for i, line in enumerate(lines):
if noqa_regex.match(line):
new_line = noqa_regex.sub(r 1 , line)
lines[i] = new_line
app.connect( autodoc-process-docstring , trim_noqa)
return app
Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...
I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...
Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...
Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...
I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...
Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...
Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...
I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...