[Python-ideas] triple-quoted strings and indendation

Ron Adam rrr at ronadam.com
Sat May 14 03:28:49 CEST 2011



On 05/11/2011 05:22 PM, Greg Ewing wrote:
> I have an idea of my own concerning multi-line strings.
>
> Many of the problems of triple-quoted strings stem from
> the fact that they're trying to be expressions that
> sit in-line with the rest of the code. As we've seen
> with all the attempts to fit multi-line function bodies
> into lambdas, that doesn't really work.
>
> So instead of a multi-line string *expression*, I think
> we need a *statement*.
>
> string adverisement:
>     | Python Egg Incubator!
>     |
>     | Hatch your eggs in half the time. Get yours
>     | today for only $39.99!


If in the above, '|' is used as the start of a line terminated string, it 
would be a nicer way of typing...

string advertisement:
     " Python Egg Incubator!\n"
     "\n"
     " Hatch your eggs in half the time. Get yours\n"
     " today for only $39.99!\n"

I think that would only require a small patch to tokanize.c.  It would 
result in a blank line being added to the end of the paragraph, but maybe 
that's not so bad.

The hard parts are finding the best symbol, '|' is already used, and 
weather or not to try to handle raw and byte strings would be a concern as 
well.

We don't want to allow quotes to go unterminated as that is usually an 
error that needs to be caught.

Weather or not it's desirable to do this is another thing.  ;-)

Cheers,
    Ron




More information about the Python-ideas mailing list