跳转到主要内容

内置函数、类型、异常和其他对象。

项目描述

该包使用修改版的Shunting Yard算法评估逻辑标签表达式。此包是cucumbers标签表达式的Python移植版本。

它也被radish使用。

Build Status PyPI package version PyPI python versions

安装

$ pip install tag-expressions

这里有一个预告

>>> from tagexpressions import parse
>>>
>>> expression = '( a and b ) or ( c and d )'
>>> compiled_expression = parse(expression)
>>> print(compiled_expression)
( ( a and b ) or ( c and d ) )
>>>
>>> data = ['a', 'b', 'c', 'd']
>>> assert compiled_expression.evaluate(data) == True
>>>
>>> data = ['a', 'c']
>>> assert compiled_expression.evaluate(data) == False
>>>
>>>
>>> expression = 'not a or b and not c or not d or e and f'
>>> compiled_expression = parse(expression)
>>> print(compiled_expression)
( ( ( not ( a ) or ( b and not ( c ) ) ) or not ( d ) ) or ( e and f ) )
>>>
>>> data = ['b', 'e', 'f']
>>> assert compiled_expression.evaluate(data) == True
>>>
>>> data = ['a', 'c', 'd']
>>> assert compiled_expression.evaluate(data) == False

用法

可用运算符

  • or - 两个给定变量的“or”连接

  • and - 两个给定变量的“and”连接

  • not - 单个变量的否定

中缀中给出的每个其他标记都视为变量。

运算符优先级

从高到低

  • ()

  • or

  • and

  • not

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源分布

tag-expressions-2.0.0.tar.gz (6.1 kB 查看哈希值)

上传时间 源代码

构建的发行版

tag_expressions-2.0.0-py3-none-any.whl (5.4 kB 查看哈希值)

上传时间 Python 3

由以下支持