python - 由 latex 中的显示方程触发的文档字符串无效转义序列

标签 python flake8

我在 Python 中的函数的文档字符串中放置了一个 latex 数学表达式。它会触发一个错误“W605 无效转义序列”,这会破坏 flake8 检查。如何解决?

"""
The test function is defined as:
\sin(\pi x)/x
"""

我现在通过使用双斜线解决了这个问题。

最佳答案

使用原始字符串作为文档字符串

import math
def do_this(x):
    r"""This doc string contains a backslash \sin(x)"""
    print(math.sin(x))
然后 flake8 不会再提示了。见 this answerPEP 257有关包含反斜杠时需要原始文档字符串这一事实的更多详细信息。

关于python - 由 latex 中的显示方程触发的文档字符串无效转义序列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61313624/

相关文章:

python - Ubuntu 通过 apt-get 安装 apache spark

python - Flask 导入未注册路由

python - flake8 - 忽略函数的警告

python - 从 Flake8 结果中过滤掉特定错误

python - 薄片 8's Mercurial hook raised an exception: ' ui' 对象没有属性 'configint'

python - flake8 没有获取配置文件

python - 警告 : toctree contains reference to nonexisting document error with Sphinx

Python:在国际号码上发送短信的脚本?

python - 如何将.html文件输出到.doc文件django

python - flake8 忽略多行警告 F405