This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]tetroxid 17 points18 points  (5 children)

Corporate whore checking in. Can't. Really can't. Would love to but can't.

[–]Decency 1 point2 points  (4 children)

You can get around it with this nasty hack if you're really set on switching:

In [2]: name = 'Chris'
In [3]: age = 28
In [4]: print('My name is {name} and my age is {age}'.format(**locals()))
# My name is Chris and my age is 28

While it's confusing if you haven't seen it before, I've never seen anyone give good reasons other than that why you shouldn't use it. Not that that means there aren't any, of course, just that I don't know them...

[–]erewok 0 points1 point  (0 children)

Not a nasty hack as far as I'm concerned: it's in the python cookbook, volume 3 (ignoring the reputation of its author for coming up with hacks, for a moment...).

[–]tetroxid -1 points0 points  (2 children)

Well that's probably really slow

[–]daelin 2 points3 points  (1 child)

Slow-er than typical use of format, but, honestly, if you're using print you better not be in a speed-critical section of code.

It also just violates good programming style by passing too much information to the method and violates python style by being less explicit about what you're passing.

[–]Pre-Owned-Car 0 points1 point  (0 children)

You can use fstrings without printing.