[Python-ideas] Draft PEP on string interpolation
Ron Adam
ron3200 at gmail.com
Tue Aug 25 04:23:42 CEST 2015
On 08/24/2015 06:45 PM, Mike Miller wrote:
>> - How problematic will it be that an e-string pins all the
>> interpolated objects in memory for its lifetime?
>
> It will be an object holding a raw template string, and a number of
> variables. In normal usage I don't suspect it to be a problem.
If an objects __str__ method could have an optional fmt='spec' argument,
then an estring, could just hold strings, and not the object references.
That also prevent surprises if the object is mutated between the time
it's estring is created and when the estring is used as a string. For
that matter it prevents an estring from printing one way at one time,
and another at another time.
I don't know if the fomatting can be split like this... Where an object
is formatted to a string representation, and then that is formatted to a
field specification. The later being things like width, fill, right,
center, and left. These are independent of the object and belong to
the string. Things like nubmer of places and sign or to use leading or
trailing zeros is part of the object being converted to a string.
Cheers,
Ron
More information about the Python-ideas
mailing list