[Python] How to get textwrap in Python to break on underscores or arbitrary characters (not...

Discussão em 'Python' iniciado por Stack, Março 27, 2025.

  1. Stack

    Stack Membro Participativo

    The following works well:

    from textwrap import fill
    print(fill("hello-there", 8))


    Outputs:

    hello-
    there


    However, I am using a lot of text where words are separated with underscores, not hyphens. The option break_on_hyphens is great but there seems to be no way to specify other separators.

    I looked around and was really surprised to not find anything on this. Does anyone have any idea of the best way to proceed?

    Continue reading...

Compartilhe esta Página