On 8/10/2015 8:00 PM, MRAB wrote: > On 2015-08-11 00:26, Victor Stinner wrote: >> Le mardi 11 août 2015, Eric V. Smith <e...@trueblade.com >> <mailto:e...@trueblade.com>> a écrit : >> >> It sounds like you want to disallow leading spaces just to >> disallow this one type of expression. >> >> >> I would like to reduce the number of subtle differences between >> f-string and str.format(). >> > I'm a little bit surprised at seeing this: > >>>> '{0}'.format('foo') > 'foo' >>>> '{ 0}'.format('foo') > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > KeyError: ' 0' >>>> '{a}'.format(a='foo') > 'foo' >>>> '{ a}'.format(a='foo') > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > KeyError: ' a' > > In some other cases, leading and trailing spaces are ignored: > >>>> int(' 0 ') > 0 > > Outside string literals, they're also ignored. > > But, then: > >>>> '{-1}'.format('foo') > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > KeyError: '-1' > > It's a string key, even though it looks like an int position.
I think there are bug tracker issues for both of these. I think the argument against changing them is that people might be depending on this behavior. I'll grant you it seems unlikely, but you never know. Eric. _______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com