[Python-ideas] Multi-line strings that respect indentation

Stephen J. Turnbull stephen at xemacs.org
Fri Nov 5 15:54:59 CET 2010


spir writes:

 > It's just reversing the point of view. The right thing would be to
 > have Python code correctly aligned on indentation _by default_.

This is plausible but I don't necessarily agree that it's the right
thing.

If I'm writing a program which writes structured text like XML, which
is conventionally indented, I actually prefer

    print("""\
<xml>
  A really uninteresting XML document.
</xml>
""")

to

    print("""\
          <xml>
            A really uninteresting XML document.
          </xml>
          """)

For one thing, in many realistic cases it's probably actually
formatted like this:

    print("""\
<xml>
""")
    print("""\
  A really uninteresting XML document.
""")
    print("""\
</xml>
""")

and it would be a real PITA trying to get that right.




More information about the Python-ideas mailing list