python - 包装超过 80 个字符的 python doctest 结果

标签 python doctest pep8

我正在尝试将我的源代码保持在 PEP8 推荐的 80 个字符 guideline 宽度之下,但不知道如何包装我的结果超过 80 个字符的 doctest。 p>

一个点头的例子:

def long_string():
    """
    Returns a string which is wider than the recommended PEP8 linewidth

    >>> print long_string()
    0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789

    """
    return '0123456789' * 10

我尝试了几种组合,包括使用 # doctest: +NORMALIZE_WHITESPACE 并尝试用换行符简单地换行。

最佳答案

刚刚想通了:

def long_string():
    """
    Returns a string which is wider than the recommended PEP8 linewidth

    >>> print long_string()
    01234567890123456789012345678901234567890123456789012345678901234567890\
12345678901234567890123456789

    """
    return '0123456789' * 10

希望对其他人有所帮助。

关于python - 包装超过 80 个字符的 python doctest 结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13395610/

相关文章:

python - doctest 本地定义的函数

python - Pandas 子集选择和 Pep8

python - 为什么 Python pep-8 强烈建议在制表符上使用空格进行缩进?

Python 风格 - 小数点后加 0

python - 调用 Python doctest 时如何启用省略号?

python - 通过键连接多个 iteratorars

python - 使用 imshow 打印一种颜色

python - 重写的哈希函数的计算值和返回值不同

Python doctests/sphinx : style guide, 如何使用它们并拥有可读的代码?

python - Pipenv 始终无法锁定并产生大量错误输出