Re:Bash $* and $@ (2017)
by pinopinopino on Sunday January 12, 2020 @02:36PM
(#22028637)
I don't know, I often miss the pipe operator in python, which makes certain things much easier.
I once created a small class to simulate this a bit, it allows you to use + as pipe operator. Wouldn't use it in production though, was just fun to write it. https://pastebin.com/eQacwLj7
[ Parent
| on HN ]
Why not use | as the pipe operator? Just use __or__ instead of __add__
I have done something similar too once in a shell-like Python CLI I worked on. Can also use __ror__ to be able to pass primitives into your commands like `[1, 2, 3] | SumCmd() | PrintCmd()`
I do agree that typing something like that, especially when working in a shell, is much nicer than having to go back and forth all the time to type `print(sum([1,2,3]))`
Here it is mentioned in a talk about Python Aesthetics by Brandon Rhodes: https://www.youtube.com/watch?v=x-kB2o8sd5c&t=8m24s
Re:Bash $* and $@ (2017)
by pinopinopino on Monday January 13, 2020 @03:47AM
(#22032860)
Oh that is possible? I am not that deep into python honestly. Looks much neater to use |.
Re:Bash $* and $@ (2017)
by krazykringle on Sunday January 12, 2020 @11:29PM
(#22031832)
Plumbum (above) matches this need in Python. It overloads | to make pipes! It makes it relatively trivial to express shell idioms in Python.
One thing I like Ruby for over Python is the function chaining, which is quite shell-pipe-ish.
I'll stick to Python, but Ruby is worth a look.
Doesn’t python have channels? The pipe is essentially a channel combined with a close message (a null object I guess) Otherwise you can do something similar with iterators and function composition. I guess the syntax isn’t quite as easy to read if you’re not used to function composition?(which seems surprisingly difficult for some beginners)
Re:Bash $* and $@ (2017)
by fiddlerwoaroof on Sunday January 12, 2020 @04:31PM
(#22029593)
Shell pipes are fairly low overhead because they are an os primitive.
I really wouldn’t call pipes “low overhead.”
Re:Bash $* and $@ (2017)
by andrewshadura on Sunday January 12, 2020 @05:23PM
(#22029984)
Tried python-sh?