Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
273 views
in Technique[技术] by (71.8m points)

Wrapping python doctest results that are longer than 80 characters

I'm trying to keep my source code under the 80 character guideline width that PEP8 recommends, but can't figure out how to wrap my doctest which has results longer than 80 characters.

A noddy example:

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

    >>> print long_string()
    0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789

    """
    return '0123456789' * 10

I've tried a couple of combinations, including using # doctest: +NORMALIZE_WHITESPACE and trying to simply wrap the line with a newline.

question from:https://stackoverflow.com/questions/13395610/wrapping-python-doctest-results-that-are-longer-than-80-characters

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Just figured out:

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

    >>> print long_string()
    01234567890123456789012345678901234567890123456789012345678901234567890
12345678901234567890123456789

    """
    return '0123456789' * 10

Hope that helps somebody else out.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...