开发者

How to use pyparsing to parse and hash strings enclosed by special characters?

The majority of pyparsing examples that I have seen have dealt with linear expressions.

a = 1 + 2

I'd like to parse mediawiki headlines, and hash them to their sections.

e.g.

Introduction goes here
==Hello==
foo
foo
===World===
bar
bar

Dict would look like:

{'Introduction':'Whoot in开发者_开发问答troduction goes here', 'Hello':"foo\nfoo", 'World':"bar\nbar"}

If I could just see one example of this "enclosed" (==HEADLINE==) parsing, I'd be able to move on to links/images/files etc.


Did you miss this wiki-like language parser in the pyParsing web site examples?

h2 = QuotedString("==")


Also, this format is not unlike a .INI file:

[section1]
a = 1
b = 3
[section2]
blah=a

Which can be parsed into a nested dictionary using this example code.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜