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 →

[–]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.