Message224871
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. |
|
Date |
User |
Action |
Args |
2014-08-05 18:35:20 | r.david.murray | set | recipients:
+ r.david.murray, serhiy.storchaka, l3u |
2014-08-05 18:35:20 | r.david.murray | set | messageid: <1407263720.37.0.0366461584088.issue22129@psf.upfronthosting.co.za> |
2014-08-05 18:35:20 | r.david.murray | link | issue22129 messages |
2014-08-05 18:35:20 | r.david.murray | create | |
|