f-string syntax deficiency?

Neal Becker ndbecker2 at gmail.com
Tue Jun 6 10:04:08 EDT 2023


The following f-string does not parse and gives syntax error on 3.11.3:

f'thruput/{"user" if opt.return else "cell"} vs. elevation\n'

However this expression, which is similar does parse correctly:

f'thruput/{"user" if True else "cell"} vs. elevation\n'

I don't see any workaround.  Parenthesizing doesn't help:
 f'thruput/{"user" if (opt.return) else "cell"} vs. elevation\n'

also gives a syntax error


More information about the Python-list mailing list