RFC PEP candidate: q'<delim>'quoted<delim> ?
Bengt Richter
bokr at oz.net
Fri Mar 8 01:28:37 EST 2002
On Fri, 08 Mar 2002 15:54:29 +1300, Greg Ewing <greg at cosc.canterbury.ac.nz> wrote:
>Bengt Richter wrote:
>>
>> The problem is to do it by using an existing source of text, without
>> changing the text, and without using an external file to delimit it.
>
>Even something like q'delim' doesn't allow you to
>easily use completely arbitrary text, because you
>still have to pick *some* string that doesn't occur
>in the text. Although you don't have to modify the
>text, you do have to inspect it in order to choose
>a suitable delimiter.
Unless you choose one with vanishingly small probability
of being included, like a generated guid. A smart editor
could do this for you. You could also generate a unique
hash that couldn't (conjecture ;-) be part of the hashed
string -- but that would be a form of scanning, and you'd
have to look ahead through the entire text before
you wrote the initial delimiter.
>
>I have another idea that doesn't suffer from that
>problem.
>
> def string my_string:
> This is a free-form string constant. Its value consists
> of all the text at this indentation level, verbatim,
> with the indentation stripped off. It can contain
> ', ", ''', """, \ or any other characters.
>
I like it, though it doesn't meet the no-changes-to-the-text requirement.
I particularly like the indent-stripping for doc-strings. Since it's
a minor variation on string parsing, I think I would tend to want to
use a variant-id prefix character instead of a special def. E.g., using your strings:
def foo():
d"
This is a free-form string constant. Its value consists
of all the text at this indentation level, verbatim,
with the indentation stripped off. It can contain
', ", ''', """, \ or any other characters.
Doc-string indentation would look nicer in code sources :)
pass
Regards,
Bengt Richter
More information about the Python-list
mailing list