Raw string statement (proposal)

Steven D'Aprano steve+comp.lang.python at pearwood.info
Sat May 26 03:55:57 EDT 2018


On Sat, 26 May 2018 08:09:51 +0300, Mikhail V wrote:

> On Fri, May 25, 2018 at 1:15 PM, bartc <bc at freeuk.com> wrote:
[...]
>> One problem here is how to deal with embedded non-printable characters:
>> CR, LF and TAB might become part of the normal source text, but how
>> about anything else? Or would you only allow text that might appear in
>> a text file where those characters would also cause issues?
> 
> This syntax does not imply anything about text. From the editor's POV
> it's just the same as it is now - you can insert anything in a .py file.
> So it does not add new cases to current state of affairs in this regard.
> But maybe I'm not completely understand your question.

Here is a string assigned to name `s` using Python's current syntax:

s = "some\ncharacters\0abc\x01\ndef\uFF0A\nhere"

How do you represent that assignment using your syntax?


And another example:

s = """this is some text
x = 'a'
y = 'b'"""
t = 'c'

How do we write that piece of code using your syntax?



>> Another thing that might come up: suppose you do come up with a
>> workable scheme, and have a source file PROG1.PY which contains such
>> raw strings.
>>
>> Would it then be possible to create a source file PROG2.PY which
>> contains PROG1.PY as a raw string? That is, without changing the text
>> from PROG1.PY at all.
> 
> Should be fine, with only difference that you must indent the PROG1.PY
> if it will be placed inside an indented suite.

Bart said WITHOUT CHANGING THE TEXT. Indenting it is changing the text.


> I was thinking about this
> nuance - I've added a special case for this in addition to the ? flag.

Oh good, another cryptic magical flag that changes the meaning of the 
syntax. Just what I was hoping for.



-- 
Steve




More information about the Python-list mailing list