Several lines of code to call functions in UNIX pipeline Style

Source: Internet
Author: User
Tags python decorator
After using Linux, you basically know its pipeline, which is to use the output of a program or command as the input of another program or command.

To put it bluntly, let's look at how python can be used to call functions in the Unix pipeline style.

# Coding = utf-8class pipe: def _ init _ (self, func): Self. func = func def _ ror _ (self, other): return self. func (other) @ pipedef add (ARGs): Return sum (ARGs) @ pipedef incr (ARG): Return Arg + 1 print [1, 2, 3] | add | incr
The principle is that the decorator + operator is overloaded. (For more information about the decorator, see <the essence of the python decorator>)
Here, the magic method _ ror _ overload operator |
It's really simple and rude. My life is short. I use python!



Several lines of code to call functions in UNIX pipeline Style

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.