Code: Alles auswählen
from textwrap import fill
def wrap_text(s, indent=None, width=72, strip_chars='\n'):
stripped = s.strip(strip_chars)
if indent is None:
indent = get_leading_spaces(stripped)
clean = ' '.join(stripped.split())
return fill(clean, width=width, initial_indent=' ' * indent,
subsequent_indent=' ' * indent)
def get_leading_spaces(s):
for (spaces, char) in enumerate(s):
if not char == ' ':
return spaces