从格式化文件创建字典

时间:2015-01-24 01:36:19

标签: python string dictionary

我希望能够读取文件post.md,如下所示:

title: Some Title
slug: some-title
author: Joe Smith
date: Jan 23 2015
tags: a, b, c, d

This is the first paragraph of the post.

This is another paragraph.

生成一个像这样的python字典:

post = {
    "title": "Some Title",
    "slug": "some-title",
    "author": "Joe Smith",
    "title": datetime.date(2015, 1, 23),
    "tags": ["a", "b", "c", "d",],
    "body": "This is the first paragraph of the post.\n\nThis is another paragraph."
}

可以稍微修改文件输入,但不能完全按照yaml,因为我想要降价突出显示。也许知道pelican's code base比我更好的人可以弄清楚它是如何在那里完成的。

1 个答案:

答案 0 :(得分:0)

正如@Carl Groner建议的那样,这可以通过Meta-Data ExtensionPython Markdown完成。