[Python-ideas] Draft2 PEP on string interpolation
Mike Miller
python-ideas at mgmiller.net
Thu Aug 27 21:43:41 CEST 2015
On 08/27/2015 11:27 AM, Guido van Rossum wrote:
> specified. E.g. I couldn't figure out what code should be produced by:
>
> a = e"Sliced {n} onions in {t1-t0:.3f} seconds."
>
> Generalizing from the only example in the specification, this would become:
>
> a = est("Sliced {n} onions in {t1-t0:.3f} seconds", n=n, t1-t0=t1-t0)
Yes, the demo does not currently handle arbitrary expressions, only .format() is
implemented.
The PEP is relying on much of the PEP 498 implementation (which I don't have at
hand), so that part is underspecified. I hope to reconcile the details if/when
the larger design is chosen.
For now, I will add the ability to pass a context dictionary at init as well as
keywords to prepare for further implementation.
> I also don't understand the claim that no str(estr) is necessary to render the
> result -- the estr implementation given at
> https://bitbucket.org/mixmastamyk/docs/src/default/pep/estring_demo.py has a
> __str__ method that renders the .rendered attribute, but without the str() call
Yes, no explicit call is necessary. When you do things like print(e'') or
e''.upper() or '' + e'', you'll get the rendered string without str().
That could be more clear, yes, and maybe not substantially different than i''.
> A solution
> might be to make estr a subclass of str, but nothing in the PEP suggests that
I originally subclassed it from str, but others on the list advised against it.
Which is preferred? Under what name is the string in a string object actually
held (if any)?
-Mike
More information about the Python-ideas
mailing list