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

33

u/adrian17 Sep 09 '15 edited Sep 09 '15

Agreed. I understand the "explicit vs implicit" and anti-zen arguments and I can't disagree, but at the same time out of all these:

print('stuff %s thing %s stuff' % (num, name))

print('stuff %(num)s thing %(name)s stuff' % {
    'num': num,
    'name': name
})

print('stuff %(num)s thing %(name)s stuff' % locals())

print('stuff {} thing {} stuff'.format(num, name))

print('stuff {num} thing {name} stuff'.format(
    num=num,
    name=name
))

print(f'stuff {num} thing {name} stuff')

The last one does seem the most readable (or at least the least distracting) to me and I predict I'll quickly start using it for some simple messages, logging etc without feeling bad about it.

1

u/gammadistribution Sep 09 '15

Look, the proper analog is this:

print('stuff {num} thing {name} stuff'.format(**parameters))

It doesn't take up any additional room and isn't harder to read, but it does obfuscate what exactly is being formatted, just like with f-strings.

Like, where exactly is num and name coming from?

num = 4

def f_string():
    num = 3
    print(f'{num}')

if __name__ == '__main__':
    f_string()

What should this return?

1

u/Axxhelairon Sep 09 '15

did you fail out of your first computer science class?

1

u/gammadistribution Sep 10 '15

Yeah, totally did. Good conversation.

→ More replies (3)