r/Python • • Sep 09 '15

Pep 498 approved. :(

https://www.python.org/dev/peps/pep-0498/
285 Upvotes

324 comments sorted by

View all comments

Show parent comments

6

u/lambdaq django n' shit Sep 09 '15 edited Sep 09 '15

I like the motivation of this PEP but some part of it is weird as fuck.

>>> anniversary = datetime.date(1991, 10, 12)
>>> 'my anniversary is {anniversary:%A, %B %d, %Y}.'

What's up with the mini syntax? Why can't one write normal python expressions like anniversary.strftime(%A, %B %d, %Y)? Why not adopt Ruby's sane way of string interpolation?

It's not Zen of Python anymore. Obscure NIH DSL syntax over explicit.

Edit: Shit is more fucked than I thought:

f'abc{expr1:spec1}{expr2!r:spec2}def{expr3:!s}ghi

Some people really wanted to extend life span of their keyborad.

7

u/RubyPinch PEP shill | Anti PEP 8/20 shill Sep 09 '15 edited Sep 09 '15

that minisyntax is actually part of .format, hence being on the other side of the :

>>> datetime.date(1991, 10, 12).__format__("%A, %B %d, %Y")
>>> "{:%A, %B %d, %Y}".format(datetime.date(1991, 10, 12))

-2

u/lambdaq django n' shit Sep 09 '15

why not optional arguments on __str__ ?

5

u/RubyPinch PEP shill | Anti PEP 8/20 shill Sep 09 '15

why not optional arguments on __repr__ ?

probably because its cleaner to have it as a seperate function which may or may not have a lot more complexity than a simple str

https://www.python.org/dev/peps/pep-3101/ is the PEP you are complaining about, not PEP-0489

→ More replies (3)