[issue22129] Please add an equivalent to QString::simplified() to Python strings

2014-08-05 Thread R. David Murray

R. David Murray added the comment:

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 ', 9)
  '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.

--
nosy: +r.david.murray

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22129
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22129] Please add an equivalent to QString::simplified() to Python strings

2014-08-03 Thread Tobias Leupold

New submission from Tobias Leupold:

It would be nice if a function equivalent to Qt's QString::simplified() would 
be added to Python's strings (cf. 
http://qt-project.org/doc/qt-4.8/qstring.html#simplified ).

I'm not sure if my approach is good or fast, but I added this function to my 
code like so: http://nasauber.de/blog/T/143/QString_simplified_in_Python

--
components: Interpreter Core
messages: 224633
nosy: l3u
priority: normal
severity: normal
status: open
title: Please add an equivalent to QString::simplified() to Python strings
type: enhancement
versions: Python 3.3

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22129
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22129] Please add an equivalent to QString::simplified() to Python strings

2014-08-03 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

This is too specialized function to be included in the stdlib ar added as a 
method to base class.

There are simpler and faster implementations of this function:

def simplify(s):
return ' '.join(s.strip().split())

or

def simplify(s):
return re.sub(r'\s+', ' ', s.strip())

Due to they simplicity there is no need to add them in Python.

--
nosy: +serhiy.storchaka
resolution:  - rejected
stage:  - resolved
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22129
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com