跳转到主要内容

文本解析函数调度器

项目描述

https://travis-ci.org/erinxocon/tpfd.svg?branch=master https://img.shields.io/pypi/v/tpfd.svg?maxAge=2592000 https://img.shields.io/pypi/l/tpfd.svg?maxAge=2592000

TPFD 是一种简单的方法来解析字符串并根据其内容执行函数。

Flask 启发,并在底层使用 Parse,这允许您使用语法规则装饰函数,如果在您的语法规则中找到一个匹配的模式,则该函数将使用您指定的关键字参数运行!非常适合解析日志并在找到的内容上执行宏操作!

示例

Aniamls.txt
Turtles are cool
Sloths are cool
Mosquitos are dumb

>>> p  = tpfd.Parser()

>>> @p.on_parse('{Animal} are cool')
    def main(animal):
        print('I like {0}.'.format(animal))

>>> p.parse_file('animals.txt')
'I like turtles.'
'I like sloths.'

>>> p.parse(['Turtles are cool', 'Sloths are cool', 'Mosquitos are dumb'])
'I like turtles.'
'I like sloths.'

>>> p.parse('Sloths are cool')
'I like sloths.'

>>> p.parse('Mosquitos are dumb')
None

>>> @p.on_find('>{}<')
    def find_example(words):
    print (words)

>>> p.find('<p>the <b>bold</b> text</p>')
'the bold text'

安装

$ pip install tpfd

注意

由于底层都是使用 parse,因此支持 parse 所支持的所有格式规范。例如:{[field name]:[format spec]}

当前功能

  • 支持解析文本文件

  • 支持接受输出文本或整数的生成器

  • 支持解析 Unicode 字符串

  • 支持使用新的 parse 方法自动解析字符串、整数和迭代器/生成器。

待办事项

  • 公开自定义类型功能,该功能由 Parse 提供

项目详情


下载文件

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

源分布

tpfd-0.2.4.tar.gz (4.3 kB 查看哈希值)

上传时间 源代码

构建分布

tpfd-0.2.4-py2.py3-none-any.whl (6.6 kB 查看哈希值)

上传时间 Python 2 Python 3

支持