Python的中缀运算符

betwixt的Python项目详细描述


在Python中很容易生成命名的中缀二进制运算符。在

演示时间:

# the only useful function in the module
>>> from betwixt import infix_operator

# any function of 2 arguments would do
>>> from fnmatch import fnmatch

# make the binary function into an operator, delimited by `*`
>>> matches = infix_operator('*', fnmatch)

# use it
>>> 'foo.txt' *matches* '*.txt'
True

# other delimiters can be used
>>> matches = infix_operator('|', fnmatch)
>>> 'foo.txt' |matches| '*.txt'
True

也可以使用装饰器窗体:

^{pr2}$

最后,betwixt expressive)别名infix_operator

>>> from betwixt import betwixt

>>> @betwixt('*')
... def joining(left, right):
...   return left.join(right)

>>> '_' *joining* ['a', 'b', 'c']
'a_b_c'

>>> split_at = betwixt('//', lambda lhs, rhs: lhs.split(rhs))

>>> 'a_b_c' //split_at// '_'
['a', 'b', 'c']

模块中提供了所有这些示例运算符和其他一些运算符 betwixt.examples。在

这个想法是从 http://code.activestate.com/recipes/384122-infix-operators/和 类似的C++黑客在Web上的代码我不能再找到了,但是没有 实际密码被盗。在

安装

pip install betwixt

发展

要运行所有测试运行:

tox

请注意,要合并来自所有tox环境的覆盖率数据,请执行以下操作:

Windows^{pr 6}$
Other^{pr 7}$

变更日志

  • PyPI的第一个版本。在

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java理解泛型   java Guava:如何自定义减少多重映射?   java无法构建实体管理器工厂JPA/Hibernate   不区分大小写的LDAP搜索   在java中同时调用所有类对象中的方法   java做高级数字计算?2.1k等于2100等。。?   java Camel netty组件:未能创建选择器   exceljava。lang.ClassCastException:ExcelStreamAction无法强制转换为com。开放交响乐团。xwork2。行动   java避免对嵌套a4j:区域进行验证   java如何使一帧在1秒内显示50次,每次显示时消失   java一个HashMap的遍历,我得到NullPointerException   windows HP Stream 8平板电脑。。。Java swing JScrollPane滚动在触摸屏上不工作   java如何在运行时根据用户/程序员的需要自动增加数组的大小?