[Python-ideas] Implicit String Concatenation

Ivan Vilata i Balaguer ivan at selidor.net
Fri Apr 13 09:43:01 CEST 2007

Greg Ewing (el 2007-04-13 a les 11:27:44 +1200) va dir::

> For Py3k, how about changing the definition of triple
> quoted strings so that indentation is stripped up
> to the level of the line where the string began?
> In other words, apply an implicit dedent() to it
> in the parser.

I'd rather make it explicit by using some string prefix a la 'r' or 'u',
'i', for instance:

>>> normal_string = """
...   foo
...     bar \
...   baz
... """
>>> print repr(normal_string)
'\n  foo\n    bar   baz\n'
>>> indented_string1 = i"""
...   foo
...     bar \
...   baz
... """
>>> print repr(indented_string1)
'foo\n  bar baz\n'
>>> indented_string2 = i"""foo
...     bar \
...   baz
... """
>>> print repr(indented_string2)
'foo\n    bar   baz\n'

As you see, strings marked with 'i' are dedented to the outer non-blank
character, and their first empty line is ignored.  I haven't meditated
this much, so some questions come to my mind:

* Is it really OK to remove the first empty line?
* How would this interact with an 'r' prefix?  Should initial space be
  kept then?  (This would effectively disable 'i'.)
* Should leading space in a line after a continuation backslash really
  be removed?

Of course the proposal can be made a lot better with some insight.  What
do you think of the basic idea?


  Ivan Vilata i Balaguer   @ Welcome to the European Banana Republic! @
  http://www.selidor.net/  @     http://www.nosoftwarepatents.com/    @
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 307 bytes
Desc: Digital signature
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20070413/fa564080/attachment.pgp>

More information about the Python-ideas mailing list