I asked gilch if it was possible to pipe outputs from python shell to bash tools, gilch answered that we could not do it directly
Maybe not entirely accurate as worded. I don’t remember exactly how this part of the conversation went, but (for example)
>>> import os; from unittest.mock import patch
>>> with os.popen('less', 'w') as p, patch('sys.stdout.write', p.write):
... copyright
...
would pop up less with the builtin copyright statement. Not as simple as the | in Bash. It might take me a while to explain how exactly how this works, but it’s basically monkeypatching stdout to pipe to less. Redirecting outputs of the python shell is not the normal way of doing things. You can be more direct about it.
You can use bash to pipe things into or out of calls to Python (or both). Python can also use variations on popen to pipe to or from other utilities, although it’s not nearly as easy as |.
Maybe not entirely accurate as worded. I don’t remember exactly how this part of the conversation went, but (for example)
would pop up less with the builtin copyright statement. Not as simple as the
|
in Bash. It might take me a while to explain how exactly how this works, but it’s basically monkeypatching stdout to pipe to less. Redirecting outputs of the python shell is not the normal way of doing things. You can be more direct about it.You can use bash to pipe things into or out of calls to Python (or both). Python can also use variations on
popen
to pipe to or from other utilities, although it’s not nearly as easy as|
.