This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author r.david.murray
Recipients l3u, r.david.murray, serhiy.storchaka
Date 2014-08-05.18:35:20
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1407263720.37.0.0366461584088.issue22129@psf.upfronthosting.co.za>
In-reply-to
Content
Actually, we more or less already do have this function in the stdlib, (I'd guess it is for pretty much the same reason that QT has it), except ours can also truncate sensibly to a given width:

  >>> import textwrap
  >>> textwrap.shorten('  lots\t of\nwhitespace\r\n ', 99999)
  'lots of whitespace'
  >>> textwrap.shorten('  lots\t of\nwhitespace\r\n ', 15)
  'lots of [...]'


That said, if you want *just* the white-space-stripping, the ' '.join(s.strip().split()) expression is just as useful and (for what it is worth) faster.
History
Date User Action Args
2014-08-05 18:35:20r.david.murraysetrecipients: + r.david.murray, serhiy.storchaka, l3u
2014-08-05 18:35:20r.david.murraysetmessageid: <1407263720.37.0.0366461584088.issue22129@psf.upfronthosting.co.za>
2014-08-05 18:35:20r.david.murraylinkissue22129 messages
2014-08-05 18:35:20r.david.murraycreate