3 ms·
Marcel (referenced elsewhere in this discussion) addresses this point exactly. I didn't want to invent another scripting language. Python is great for that purp
by geophile 6y ago
Marcel (referenced elsewhere in this discussion) addresses this point exactly. I didn't want to invent another scripting language. Python is great for that purpose, except that, as you point out, shelling out is painful. So marcel includes a module, marcel.api, which gives you access to marcel shell capabilities inside of Python. The example I gave elsewhere explores a directory recursively, finds .c and .h files, and counts the lines in them. The shell command was this:
ls -fr \
| select (f: f.suffix in ('.c', '.h')) \
| map (f: f.read().count('\n')) \
| red +
In Python, it would be:
from marcel.api import *
print(first(ls(file=True, recursive=True) |
select(lambda f: f.suffix in ('.c', '.h')) |
map(lambda f: f.read().count('\n')) |
red('+')))
You can see that the ls, select, map, and red commands are called directory from the Python code, without having to call Popen, os.system(), etc. Each version of the code (shell, script) runs in one Python process, (not one process per command).
- phillco 6y agoThanks!