[Python-ideas] New str whitespace cleaning method?

Wolfgang Maier wolfgang.maier at biologie.uni-freiburg.de
Fri May 24 21:47:06 CEST 2013


Joao S. O. Bueno <jsbueno at ...> writes:

> 
> Come on - this is Python, and we are talking about entering a string in code -
> One doe snto want to do a "from myutils.stringutils import dedenter"
> just to be able
> to use long strings in code. - in other languages it might be normal to
> go to arbtirary leenghts of boiler plate code to do trivial stuff.
> 
> But ..seeing the attention here, I guess I am indeed one of the 2 programmers
> in the World who needs long strings with no white-space from indentation
> in code and consider it should be part of the syntax, not a
> possibility on the stdlib,
> so..whatever.  :-/
> 

I guess the problem is not that nobody has a need for it, but rather that
there are many different types of behaviour of that formatting method that
one could imagine. You gave a few examples yourself and, personally, I'd
prefer that method to remove a fixed specified number of spaces from the
beginning of each line, so that you could do things like:

if format_output:
    print ("""\
                 1)
                       Indent *only* the first line
                    of a  paragraph,
                 2)
                    Have pretty-formatted numbered
                    lists  
                 independent of the code indentation level.""".ltrim(16))

I think, it's easy enough to come up with solutions to everybodies
preferences, but that doesn't mean that they have to be built into python.
Best,
Wolfgang



More information about the Python-ideas mailing list