adventurelib.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:adventurelib 作者: lordmauve 项目源码 文件源码
def say(msg):
    """Print a message.

    Unlike print(), this deals with de-denting and wrapping of text to fit
    within the width of the terminal.

    Paragraphs separated by blank lines in the input will be wrapped
    separately.

    """
    msg = str(msg)
    msg = re.sub(r'^[ \t]*(.*?)[ \t]*$', r'\1', msg, flags=re.M)
    width = get_terminal_size()[0]
    paragraphs = re.split(r'\n(?:[ \t]*\n)', msg)
    formatted = (textwrap.fill(p.strip(), width=width) for p in paragraphs)
    print('\n\n'.join(formatted))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号