4 ms·
Pretty much anything longer then a throwaway one liner I write in python. Would be cool if python had a pipe operator though. The back ticks in ruby is pretty
by tayo42 11mo ago
Pretty much anything longer then a throwaway one liner I write in python.
Would be cool if python had a pipe operator though.
The back ticks in ruby is pretty ergonomic too. Wish python had a simpler way to run commands. Kind of tedious to look up subprocess run arguments and also break things up into arrays.
- mackeye 11mo agonushell (https://www.nushell.sh/ https://www.nushell.sh/) is essentially perfect for this use case! i use it rather than posix(y) shells for most projects where id normally reach for python.
- kstrauser 11mo agoYou can always set shell=True and pass in an entire command line as a string, but… don’t do that. It seems really nice until the first time you get the shell escaping wrong, and then it’s something you tend never to do again. For example, subprocess.run(“rm -rf ~/ some file”, shell=True) and subprocess.run([“rm”, “-rf”, “~/ some file”]) have significant different behavior.
- lgas 11mo agoWhat is the difference in behavior? They both look like they would delete the user's home directory. I assume the latter would try to delete a directory literally named with a tilde instead?
- kstrauser 11mo agoThe latter passes each item in the list into the child processes’s argv, as-is, without the shell parsing them. That means this would delete a single item named “~/ some file”, spaces and all, instead of three items named “~/“, “some”, and “file”. Edit: I’m typing this on my phone, so brevity won over explicitness. The latter probably wouldn’t expand ~. Imagine a file named “/home/me/ some file” for a better example.
- vovavili 11mo agocytoolz.pipe (https://toolz.readthedocs.io/en/latest/api.html#toolz.functoolz.pipe https://toolz.readthedocs.io/en/latest/api.html#toolz.functo...), cytoolz's curried namespace (https://toolz.readthedocs.io/en/latest/curry.html#the-curried-namespace https://toolz.readthedocs.io/en/latest/curry.html#the-currie...) and method chaining can pretty much fully replace a pipe operator. The only problem is that you don't really want to write anonymous functions in Python with its needlessly verbose syntax, and long pipes are kind of limited without that.