[Python-ideas] Custom string prefixes

Steven D'Aprano steve at pearwood.info
Tue May 28 03:10:32 CEST 2013


On 28/05/13 05:41, Haoyi Li wrote:
> The scala people intend to use their version of this for things like xml
> literals:
>
> snippet = xml"<h>hello world!</h1>"
>
> Which are parsed and interned at compile time. Generally, it would be
> useful for embedding snippets of non-python code in strings within a python
> program, and have them resolved at import-time and interned to prevent
> run-time errors or performance overheads.

"Prevent run-time errors" is not generally something that Python cares about, or could do even if it tried. In any case, that's not going to be practical for Python, since the xml function won't exist at compile-time. It won't exist until import-time, which is at run-time.

But I wonder, why would you want your XML to be interned? I don't think I'd want large amounts of verbose XML in memory long after I've finished with it.



-- 
Steven


More information about the Python-ideas mailing list