[Python-ideas] New str whitespace cleaning method?
Serhiy Storchaka
storchaka at gmail.com
Tue May 21 17:19:40 CEST 2013
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))
More information about the Python-ideas
mailing list