[issue15510] textwrap.wrap('') returns empty list

Antoine Pitrou report at bugs.python.org
Fri Aug 3 23:28:30 CEST 2012


Antoine Pitrou added the comment:

> Really.
> 
> --> ''.split('\n')
> ['']

You claimed that an empty list is not a list of lines. I countered that
splitlines(), which *by definition* returns a list of lines, can return
an empty list, therefore textwrap.wrap() is not exotic in its behaviour.
Whether or not split() behaves differently is irrelevant.

> So if you have code that loops over the return and prints it out:
> 
> for line in wrap(blah):
>      print(line)
> 
> you will have different output with [] than with [''].

Indeed, which is a good reason *not* to change textwrap.wrap's
behaviour. The current behaviour is as reasonable as any other, and
changing it would break compatibility.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue15510>
_______________________________________


More information about the Python-bugs-list mailing list