diff --git a/Lib/textwrap.py b/Lib/textwrap.py index 7ca393d1c371aa..6c1a2112931659 100644 --- a/Lib/textwrap.py +++ b/Lib/textwrap.py @@ -475,18 +475,22 @@ def indent(text, prefix, predicate=None): it will default to adding 'prefix' to all non-empty lines that do not consist solely of whitespace characters. """ + prefixed_lines = [] + if predicate is None: # str.splitlines(True) doesn't produce empty string. # ''.splitlines(True) => [] # 'foo\n'.splitlines(True) => ['foo\n'] - # So we can use just `not s.isspace()` here. - predicate = lambda s: not s.isspace() - - prefixed_lines = [] - for line in text.splitlines(True): - if predicate(line): - prefixed_lines.append(prefix) - prefixed_lines.append(line) + # So we can use just `not line.isspace()` here. + for line in text.splitlines(True): + if not line.isspace(): + prefixed_lines.append(prefix) + prefixed_lines.append(line) + else: + for line in text.splitlines(True): + if predicate(line): + prefixed_lines.append(prefix) + prefixed_lines.append(line) return ''.join(prefixed_lines)
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: