[Python-ideas] New str whitespace cleaning method?

Andrew Barnert abarnert at yahoo.com
Tue May 21 17:52:42 CEST 2013


On May 21, 2013, at 8:19, Serhiy Storchaka <storchaka at gmail.com> wrote:

> 21.05.13 17:18, Joao S. O. Bueno написав(ла):
>> On 21 May 2013 09:52, Serhiy Storchaka <storchaka at gmail.com> wrote:
>>> 21.05.13 15:07, Joao S. O. Bueno написав(ла):
>>>> What about an STR method for just formatting whitespace?
>>>> I propose starting with something that would just replace all occurrences of
>>>> white-space sequences with a single white-space,
>>> ' '.join(text.split())
>> 
>> Indeed, this describes the intented effect -
>> but for "day to day" coding, it implies changing the code that goes
>> 
>> message("my long string "
>>                 "bla bla bla "
>>                )
>> 
>> for
>> 
>> message (" ".join("""my long string
>>                                 bla bla bla""".split()))
>> 
>> Which does not exactly fits my concept of a readable and simple way to
>> enter long strings.
> 
> Of course you can define a one-line function.
> 
> def STR(text): return ' '.join(str.split(text))

If you read his example, he's clearly looking for a method on the str class, not a free function (presumably to avoid having to add even more stuff to the left of the string that would force you to indent it even further and therefore potentially wrap to even more lines).


More information about the Python-ideas mailing list