A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2015-August/141201.html below:

[Python-Dev] PEP 498 f-string: please remove the special case for spaces

[Python-Dev] PEP 498 f-string: please remove the special case for spacesMRAB python at mrabarnett.plus.com
Tue Aug 11 02:00:15 CEST 2015
On 2015-08-11 00:26, Victor Stinner wrote:
> Le mardi 11 août 2015, Eric V. Smith <eric at trueblade.com
> <mailto:eric at 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.

More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4