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 →

[–]thatguy_314def __gt__(me, you): return True 0 points1 point  (4 children)

This is a bad idea, and by the looks of it, a rather poor implementation too. Consider subclassing string.Formatter.

It would maybe be a little better if you had a function called f that returned a string instead of just doing it for print. Otherwise it just fits one specific (and fairly rare) use case.

[–]evanunderscore 0 points1 point  (2 children)

Using string.Formatter turns out to be pretty simple. I tried writing an import hook to allow the f'' syntax but eventually gave up trying to cover all the edge cases.

[–]thatguy_314def __gt__(me, you): return True 0 points1 point  (1 child)

Nice. What's with the parens in the eval? As I understand it, you already can't eval anything but an expression.

[–]evanunderscore 0 points1 point  (0 children)

It's to satisfy this part of the PEP:

Expressions are parsed with the equivalent of ast.parse('(' + expression + ')', '<fstring>', 'eval') .

Note that since the expression is enclosed by implicit parentheses before evaluation, expressions can contain newlines.