textwrap.TextWrapper width=None (or Inf)

Hi, I wonder why nobody asked on bugs.python.org for rather obvious functionality of being able to reflow a paragraph to one line? Meaning, that any paragraph would be stripped of all whitespace (etc. ... whatever is configured by the additional parameters of the TextWrapper class) and then joined into long line. I know that ''.join(text.splitlines()) does something similar, but a) it doesn't handle all whitespace munging, b) it just seems like an obvious functionality for TextWrapper to have. Any thoughts on it? Should I just file a bug? Best, Matěj -- http://www.ceplovi.cz/matej/, Jabber: mcepl<at>ceplovi.cz GPG Finger: 89EF 4BC6 288A BF43 1BAB 25C3 E09F EF25 D964 84AC [...] a superior pilot uses his superior judgment to avoid having to exercise his superior skill. -- http://www.jwz.org/blog/2009/09/that-duct-tape-silliness/#comment-10653

On 12/26/2013 5:17 PM, Matej Cepl wrote:
I wonder why nobody asked on bugs.python.org for rather obvious functionality of being able to reflow a paragraph to one line?
Because width=4000000000 should do just that?
Any thoughts on it? Should I just file a bug?
It would be an enhancement request, not a bug report, but it seems not needed. -- Terry Jan Reedy

On Thu, Dec 26, 2013 at 11:17:34PM +0100, Matej Cepl wrote:
Possibly because nobody needed the functionality? Or because they didn't think that *wrapping* a long line into a paragraph and *unwrapping* a paragraph into a single line should be handled by the same function?
I would expect that you should use ' '.join, rather than the empty string. Otherwises lines will be incorrectly concatenated: """the cat in the hat""" => "the cat inthe hat"
a) it doesn't handle all whitespace munging,
Can you given an example of what whitespace munging it fails to handle?
b) it just seems like an obvious functionality for TextWrapper to have.
py> text = """the cat in ... the hat""" py> textwrap.wrap(text, width=len(text)) ['the cat in the hat'] Is there a case that this does not handle? Perhaps this is not obvious enough. A simple helper function may increase discoverability: def unwrap(text): return wrap(text, width=len(text)) -- Steven

On 12/26/2013 5:17 PM, Matej Cepl wrote:
I wonder why nobody asked on bugs.python.org for rather obvious functionality of being able to reflow a paragraph to one line?
Because width=4000000000 should do just that?
Any thoughts on it? Should I just file a bug?
It would be an enhancement request, not a bug report, but it seems not needed. -- Terry Jan Reedy

On Thu, Dec 26, 2013 at 11:17:34PM +0100, Matej Cepl wrote:
Possibly because nobody needed the functionality? Or because they didn't think that *wrapping* a long line into a paragraph and *unwrapping* a paragraph into a single line should be handled by the same function?
I would expect that you should use ' '.join, rather than the empty string. Otherwises lines will be incorrectly concatenated: """the cat in the hat""" => "the cat inthe hat"
a) it doesn't handle all whitespace munging,
Can you given an example of what whitespace munging it fails to handle?
b) it just seems like an obvious functionality for TextWrapper to have.
py> text = """the cat in ... the hat""" py> textwrap.wrap(text, width=len(text)) ['the cat in the hat'] Is there a case that this does not handle? Perhaps this is not obvious enough. A simple helper function may increase discoverability: def unwrap(text): return wrap(text, width=len(text)) -- Steven
participants (3)
-
Matej Cepl
-
Steven D'Aprano
-
Terry Reedy