如何在Python中轻松为自定义格式的数据创建解析器 [英] How to easily create a parser for custom formatted data in Python

查看:128
本文介绍了如何在Python中轻松为自定义格式的数据创建解析器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文件中的格式化数据类似于 YAML ,并希望创建语法和解析器为了它.在Python中执行此操作的简便方法是什么?是否有工具可以让您为数据定义语法并根据语法进行解析?

The formatted data in file is similar to YAML and would like to create a grammer and parser for it. What is the easies way to do this in Python? Is there a tool that let you define a grammer for your data and parses according to the grammer?

P.S.我知道更简单的方法可能是将数据格式更改为JSON或其他类型,但现在无法更改

P.S. I know the easier way to do this might be to change the data formate into JSON or other type but right now it can't be changed

推荐答案

查看pyparsing.这是一个非常简单的库,但是它也很强大.

Look into pyparsing. It's a pretty simple library, but it is also quite powerful.

这篇关于如何在Python中轻松为自定义格式的数据创建解析器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆