用于读取扩展文件内容和元数据的python模块
econtent的Python项目详细描述
扩展内容阅读器
版权所有(c)2016-2017 david betz
安装
pip install econtent
兼容性
python 2和3
目的
文件有内容和元数据。降价已经帮助我们 无聊的文本文件到富文本(没有rtf或专有的巫术),但是 这还不够。我的内容需要节和元数据。他们 已经有了创建日期和修改日期,但我经常需要 覆盖这些。这就是这个组件的来源。一直在帮你 我已经有几年了(这是我的python重构/端口 原始/生产/更复杂的.NET版本)。
如果你只看这个例子,就更容易理解了…
下面的例子很荒谬,但它是 您可以存储在文件中的内容:
item01.txt
hollow unbraced needs mineral high fingerd strings red tragical having definement invisible@@footnote|78@@. flames grow pranks obey hearsed variable grandsire bodykins possessd worser oerthrown oerweigh healthful kingly wise faculty loggats best. unfortified chopine hill witchcraft countries toward nerve grief duty rivals. @@begin|format:javascript@@ alert((function() { var item = 'item01'; return item.split('').reverse() })()); @@format:python@@ print('item01'[::-1]) @@end@@ patience unhouseld pours lapsed would passion point blastments lady spectators. @author@ Billy Speareshakes @title@ Thy Wonderful Randomious @page@ 728 @footnote|78@ nose thee something disclaiming wrung antiquity rend illume halt osric list @_created@ 2016-07-27T19:38:10Z @_modified@ 2016-07-27T19:38:10Z
有两段,后面是一个javascript块,然后是 一块python,然后是另一段,然后是一堆元数据。是的 一个重述的例子,因为它结合了两个研究的概念 网站(引文和脚注)和我的 netfxharmonics.com网站(javascript 在最终呈现的上下文中,将使用 javascript彩色语法)。
当前的python项目将该文件读取为以下对象:
{ '_': { 0: 'hollow unbraced needs mineral high fingerd strings red tragical having definement invisible@@footnote|78@@. flames grow pranks obey hearsed variable grandsire bodykins possessd worser oerthrown oerweigh healthful kingly wise faculty loggats best.\nunfortified chopine hill witchcraft countries toward nerve grief duty rivals.', 1: { 0: { '_': " alert((function() {\n var item = 'item01';\n return item.split('').reverse()\n })());", 'format': 'javascript' }, 1: { '_': " print('item01'[::-1])", 'format': 'python' } }, 2: 'patience unhouseld pours lapsed would passion point blastments lady spectators.', }, 'author': 'Billy Speareshakes', 'title': 'Thy Wonderful Randomious', 'page': '728', 'footnote': { 78: 'nose thee something disclaiming wrung antiquity rend illume halt osric list', }, '_created': '2016-07-27T19:38:10Z', '_modified': '2016-07-27T19:38:10Z', '_filename': 'item01.txt', '_extension': 'txt', '_basename': 'item01', }
这是非常有用的信息 正在分析文件内部。
从中读取创建、修改、文件名、扩展名和basename 但是创建和修改的文件元数据可以使用 @创建了@和@修改了@标记。
但是,不仅仅是元数据。在我的技术网站上,我需要颜色 各种编程语言的语法。预格式化生成代码 不可读。所以,我需要节(@@开始…@@/@@结束@)。关于我的研究 网站上,我需要大量的引文和脚注。所以,我需要 可链接内容(@xxxx@)。
有关用法,请参见test_read.py。
用例
- 一个条目==博客条目
- 一个条目==一个引用(带引用数据)
- 一个条目=一个podcast mp3;您可以使用类似@audio的内容@ 它将告诉您的自定义系统此条目正在描述 那个特别的MP3