Re: [Python-ideas] Running Python commands from a Shell (was: Option of running shell/console commands inside the REPL)
On Fri, Feb 01, 2019 at 02:38:43PM -0600, Dan Sommers wrote: > So why not turn that around? ksh (since way back when) and > bash (since 2008, according to what I read somewhere online) > have "co-processes," which allow you to run a command "in > the background," and send commands and receive replies from > it. So I tried it with Python, but it didn't work: > > $ coproc P3 { python3; } > $ echo 'import sys; print(sys.version)' >&${P3[1]} > $ read v <&${P3[0]} > [the read command just waits forever] This is another good example of the problem James was referring to in the thread about clearer communication. Don't assume we all know what coproc does. > A pile of experiments and examples from web pages later, I > think it's Python and not me. My example, with suitable > changes to the literal in the echo command, works with sbcl > and erl, but not python3. If I start python3 as follows: What are sbcl and erl? I'm guessing you don't mean antimony pentachloride and a municipality in Austria. Possibly Steel Bank Common Lisp and Erlang? But I'm not confident about that. Does your example work with more well-known interpreted languages with interactive interpreters such as Ruby, Lua, Javascript (outside of the browser), etc? -- Steve ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
Re: [Python-ideas] Running Python commands from a Shell (was: Option of running shell/console commands inside the REPL)
On Sat, Feb 2, 2019 at 7:39 AM Dan Sommers <2qdxy4rzwzuui...@potatochowder.com> wrote: > > On 2/1/19 2:26 AM, João Matos wrote: > > Hello, > > > > > > Consider adding the option of running shell/console commands inside the > > REPL. > > Something like > !dir (This might be better on python-list rather than here) > I first ran into this in the days of teletypes and dumb > terminals, where other programs let you run shell commands > from inside them. Now the shoe appears to be on the other > foot. > > So why not turn that around? ksh (since way back when) and > bash (since 2008, according to what I read somewhere online) > have "co-processes," which allow you to run a command "in > the background," and send commands and receive replies from > it. So I tried it with Python, but it didn't work: > > $ coproc P3 { python3; } > $ echo 'import sys; print(sys.version)' >&${P3[1]} > $ read v <&${P3[0]} > [the read command just waits forever] Looks like you may have a problem with output buffering. Try running "python3 -u" to tell it to run stdout/stderr unbuffered - otherwise, Python assumes that its output is going to a file and it won't matter. Alternatively, explicitly flush stdout after output, which could be done with a display hook: _old_hook = sys.displayhook def display(obj): _old_hook(obj) sys.stdout.flush() sys.displayhook = display But unless you're expecting a lot of output, it's probably easier and just as effective to simply use "-u". ChrisA ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
Re: [Python-ideas] Running Python commands from a Shell (was: Option of running shell/console commands inside the REPL)
On 2/1/19 2:26 AM, João Matos wrote: Hello, Consider adding the option of running shell/console commands inside the REPL. Something like !dir I first ran into this in the days of teletypes and dumb terminals, where other programs let you run shell commands from inside them. Now the shoe appears to be on the other foot. So why not turn that around? ksh (since way back when) and bash (since 2008, according to what I read somewhere online) have "co-processes," which allow you to run a command "in the background," and send commands and receive replies from it. So I tried it with Python, but it didn't work: $ coproc P3 { python3; } $ echo 'import sys; print(sys.version)' >&${P3[1]} $ read v <&${P3[0]} [the read command just waits forever] A pile of experiments and examples from web pages later, I think it's Python and not me. My example, with suitable changes to the literal in the echo command, works with sbcl and erl, but not python3. If I start python3 as follows: $ coproc P3 { python3 | tee /tmp/P3; } then I can see the empty /tmp/P3 file, and the python3 and tee processes, but /tmp/P3 remains empty. Any ideas as to why not? Thanks, Dan ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/