标签:tar ret details 调用 .net ref other href int
废话少说,以下我们看用python怎么实现unix管道风格的函数调用.
#coding=utf-8
class Pipe:
def __init__(self, func):
self.func = func
def __ror__(self, other):
return self.func(other)
@Pipe
def add(args):
return sum(args)
@Pipe
def incr(arg):
return arg + 1
print [1, 2, 3] | add | incr
原理就是装饰器+操作符重载.(对装饰器一知半解的请看<python装饰器的本质>)
飘逸的python - 几行代码实现unix管道风格的函数调用
标签:tar ret details 调用 .net ref other href int
原文地址:http://www.cnblogs.com/yangykaifa/p/6725990.html