[Python-ideas] Briefer string format
Mike Miller
python-ideas at mgmiller.net
Mon Aug 3 09:05:09 CEST 2015
On 08/02/2015 07:43 PM, Eric V. Smith wrote:
> On 8/2/2015 7:46 PM, Mike Miller wrote:
>> I don't understand how we got to arbitrary expressions.
> I think here:
> https://mail.python.org/pipermail/python-ideas/2015-July/034701.html
In that message, GvR seems to be exploring the options. I could be wrong, but
from reading again, he appears to favor keeping it to .format() syntax?
>> There was probably an edge case or two, but I wasn't expecting
Did anyone discover the strategy below wasn't possible (moving the identifiers)?
f'{x}{y}' --> '{}{}'.format(x, y)
f'{x:10}{y[name]}' --> '{:10}{[name]}'.format(x, y)
> Also, what'syour concern with the suggested approach? There are no security concerns
> as there would be with eval-ing arbitrary strings.
That's true I suppose, and perhaps I'm being irrational but it feels like a
complex solution, a pandora's box if you will. To put it another way, it's way
more power than I was expecting. It's rare that I use even the advanced
features of .format() as it is.
I'm guessing that despite the magic happening behind the scenes, people will
still think of the format string as an (interpolated) string, like the shell.
If they want to write arbitrary expressions they can already do that in python
and then format a string with the answers. This will be another way to write
code, that's (as far as I know) not strictly necessary.
Also I thought, that the simpler the concept, the greater likelihood of PEP
acceptance. Binding the format string to .format() does that, in the mind at
least, if not the implementation.
Still, if this is what most people want, I'll keep quiet from now on. ;)
(Thanks for taking this on, btw.)
-Mike
More information about the Python-ideas
mailing list