<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div style="-webkit-text-size-adjust: auto; ">On Jun 30, 2013, at 18:09, Steven D'Aprano <<a href="mailto:steve@pearwood.info">steve@pearwood.info</a>> wrote:</div><div style="-webkit-text-size-adjust: auto; "><br></div><blockquote type="cite" style="-webkit-text-size-adjust: auto; "><div><span>Hi nbv4, and welcome.</span><br><span></span><br><span>On 01/07/13 10:32, nbv4 wrote:</span><br><blockquote type="cite"><span>The tripple quote string literal is a great feature, but there is one</span><br></blockquote><blockquote type="cite"><span>problem. When you use them, it forces you to break out of you're current</span><br></blockquote><blockquote type="cite"><span>indentation which maks code look ugly. I propose a new way to define a</span><br></blockquote><blockquote type="cite"><span>triple back quote that woks the same way regular triple quotes work, but</span><br></blockquote><blockquote type="cite"><span>instead does some simple parsing of the data within the quotes to preserve</span><br></blockquote><blockquote type="cite"><span>the flow of the code. Due to the brittle and sometimes ambigious nature of</span><br></blockquote><blockquote type="cite"><span>anything 'automatic', this feature is obviously not meant for data where</span><br></blockquote><blockquote type="cite"><span>exact white space is needed. It would be great for docstrings, exception</span><br></blockquote><blockquote type="cite"><span>messages and other type text.</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>Here is a short example of it's usage:</span><br></blockquote><blockquote type="cite"><span><a href="https://gist.github.com/priestc/5897602">https://gist.github.com/priestc/5897602</a></span><br></blockquote><span></span><br><span></span><br><span>For something as trivial as the example you give, there is no need to send people off to a website, which they may not have access too. Here's the simplified version:</span><br><span></span><br><span># Proposed syntax</span><br><span>def func():</span><br><span>    s = """line 1</span><br><span>    line 2</span><br><span>    line 3"""</span><br><span>    t = ---line 1</span><br><span>    line 2</span><br><span>    line 3---</span><br><span>    return s, t</span><br><span></span><br><span>The difference being, lines 2 and 3 of s will begin with four spaces, while t reduces the whitespace between lines to a single space:</span><br><span></span><br><span>s == 'line 1\n    line 2\n    line 3'</span><br><span>t == 'line 1 line 2 line 3'</span><br><span></span><br><span>I don't think this is particularly useful. I would be more interested in it if it kept the newlines but got rid of the leading spaces:</span><br><span></span><br><span>t == 'line 1\nline 2\nline 3'</span><br><span></span><br><span></span><br><span>but in either case, I think the choice of --- as delimiter is ugly and arbitrary, and very likely is ambiguous (currently, x = ---1 is legal code). </span></div></blockquote><div style="-webkit-text-size-adjust: auto; "><br></div><div style="-webkit-text-size-adjust: auto; ">The proposal used backticks, not hyphens:</div><div style="-webkit-text-size-adjust: auto; "><br></div><div><pre class="line-pre" style="width: 1534px; margin-top: 0px; margin-bottom: 0px; padding: 0px; "><div class="line" id="file-gistfile1-txt-LC24"><font face="Helvetica"><span style="white-space: normal; background-color: rgba(255, 255, 255, 0);">        print ```</span></font></div><div class="line" id="file-gistfile1-txt-LC25"><font face="Helvetica"><span style="white-space: normal; background-color: rgba(255, 255, 255, 0);">        Now my code looks much better. The output of this</span></font></div><div class="line" id="file-gistfile1-txt-LC26"><font face="Helvetica"><span style="white-space: normal; background-color: rgba(255, 255, 255, 0);">        function is as if you had written it in the same way</span></font></div><div class="line" id="file-gistfile1-txt-LC27"><font face="Helvetica"><span style="white-space: normal; background-color: rgba(255, 255, 255, 0);">        its written in the code above, except with all newlines</span></font></div><div class="line" id="file-gistfile1-txt-LC28"><font face="Helvetica"><span style="white-space: normal; background-color: rgba(255, 255, 255, 0);">        replaced with spaces and big swaths of spaces removed.</span></font></div><div class="line" id="file-gistfile1-txt-LC29"><font face="Helvetica"><span style="white-space: normal; background-color: rgba(255, 255, 255, 0);">        ```</span></font></div><div class="line" id="file-gistfile1-txt-LC30"><br></div></pre></div><div style="-webkit-text-size-adjust: auto; ">So, both the ambiguity and a lot of the ugliness you complain about aren't in the proposal at all.</div><div style="-webkit-text-size-adjust: auto; "><br></div><div style="-webkit-text-size-adjust: auto; ">That being said, I don't really like the proposal, and at least half of the alternatives suggested last time this came up a few months ago were better.</div></body></html>