Noam Raphael wrote:
Following Avi's suggestion, can I raise this thread up again? I think that Reinhold's .dedent() method can be a good idea after all.
The idea is to add a method called "dedent" to strings. It would do exactly what the current textwrap.indent function does.
You are missing a point here: string methods were introduced to make switching from plain 8-bit strings to Unicode easier.
As such they are only needed in cases where an algorithm has to work on the resp. internals differently or where direct access to the internals makes a huge difference in terms of performance.
In your use case, the algorithm is independent of the data type interals and can be defined solely by using existing string method APIs.
The motivation is to be able to write multilined strings easily without damaging the visual indentation of the source code, like this:
def foo(): msg = '''\ From: %s To: %s\r\n' Subject: Host failure report for %s Date: %s
%s '''.dedent() % (fr, ', '.join(to), host, time.ctime(), err)
Writing multilined strings without spaces in the beginning of lines makes functions harder to read, since although the Python parser is happy with it, it breaks the visual indentation.
This is really a minor compiler/parser issue and not one which warrants adding another string method.