It would be nice to add the following syntax sugar in Python "Print and Eval" like `ptev a == b` It is same as `statement = "a == b"; print(f"{statement} ? {eval(statement)}")`. It would super nice for debugging and other research project.
On Tue, Nov 2, 2021 at 1:31 PM Evan Greenup via Python-ideas <python-ideas@python.org> wrote:
It would be nice to add the following syntax sugar in Python "Print and Eval"
like `ptev a == b` It is same as `statement = "a == b"; print(f"{statement} ? {eval(statement)}")`.
It would super nice for debugging and other research project.
At the REPL, that basically already happens, but if this is something you're doing a lot of in your code, you might be able to take advantage of this feature of f-strings:
a = 5 b = 5.0 f"{a == b = }" 'a == b = True'
Very handy for quick debugging. ChrisA
Are you familiar with the f-string self-documentation operator in python 3.8? https://docs.python.org/3/whatsnew/3.8.html#f-strings-support-for-self-docum... With it you can say: print(f"{a==b=}") --- Ricky. "I've never met a Kentucky man who wasn't either thinking about going home or actually going home." - Happy Chandler On Mon, Nov 1, 2021 at 10:31 PM Evan Greenup via Python-ideas < python-ideas@python.org> wrote:
It would be nice to add the following syntax sugar in Python "Print and Eval"
like `ptev a == b` It is same as `statement = "a == b"; print(f"{statement} ? {eval(statement)}")`.
It would super nice for debugging and other research project.
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/NQ6NZI... Code of Conduct: http://python.org/psf/codeofconduct/
Hi Evan, f-strings support a version of this. If you put an equals sign at the end of the expression in your f-string (possibly with white space) then the f-string will include both the expression itself and its value in the result: >>> a = 12; b = 13 >>> f'{a == b}' 'False' >>> f'{a == b = }' 'a == b = False' -- Steve
participants (4)
-
Chris Angelico
-
Evan Greenup
-
Ricky Teachey
-
Steven D'Aprano