-0 from me. It’s convenient, but pre-importing sys (or math, or random, …) would also be useful. There’s too much potential for scope creep. And it’s not that hard to write a helper:
function pyx {
py -c "import sys; exec(compile(sys.argv[1], '-', 'single'))" $args
}
This has the same issue as your proof of concept regarding printing every expression. But it can be fixed just as easily here as in the PoC.
And in fact, the package pypyp offers all this, and a whole lot more:
❯ uvx pypyp sys.version
3.13.3 (tags/v3.13.3:6280bb5, Apr 8 2025, 14:47:33) [MSC v.1943 64 bit (AMD64)]
❯ uvx pypyp math.pi
3.141592653589793
❯ uvx pypyp "random.random()"
0.07559649122845125