文本解析函数调度程序
tpfd的Python项目详细描述
tpfd是一种根据字符串内容解析字符串和执行函数的简单方法。
受Flask的启发,并在引擎盖下使用Parse,这允许您用语法规则装饰函数,如果找到与您的语法规则之一匹配的模式,则函数将使用您指定的一组关键字参数运行并传递给它!非常适合分析日志和执行宏!
示例
Aniamls.txtTurtlesarecoolSlothsarecoolMosquitosaredumb>>>p=tpfd.Parser()>>>@p.on_parse('{Animal} are cool')defmain(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('>{}<')deffind_example(words):print(words)>>>p.find('<p>the <b>bold</b> text</p>')'the bold text'
安装
$ pip install tpfd
注释
parse支持的任何格式规范都受这个库的支持,因为它都是在幕后解析的。 示例:{[field name]:[format spec]}
当前功能
- 支持分析文本文件
- 支持接受输出文本或整数的生成器
- 支持解析Unicode字符串
- 支持使用新的parse方法自动分析字符串、int和interator/generator。
待办事项
- 公开Parse已经提供的自定义类型功能