从文件中摘录标记样式注释

excerpts的Python项目详细描述


https://gitlab.com/fvafrCU/excerpts/badges/master/pipeline.svghttps://gitlab.com/fvafrCU/excerpts/badges/master/coverage.svghttps://img.shields.io/pypi/v/excerpts.svg

简介

读过或写过包含分区注释的源文件吗? 尤其是在科学和/或数据分析脚本中,我很喜欢

### Collect Data

###### Remove Outliers###

甚至

### 2.1 Descriptive Statistics

RStudio,用于 programming language R有 甚至想出他们自己的 code sectioning and folding feature 需要像

# Hypothesis Testing ----

如果这些注释是标记样式的节注释,我们可以将其摘录并 设置目录。

第一个示例

假设您有以下代码:

#!/usr/bin/env python3

# #% A Tutorial Introduction

# ##% Getting Started

# no need to import anything
print('hello, world')

# ###% The First Python Function
def main():
    print('hello, world')


main()

# ##% Variables and Arithmetic Expressions
print('some code')

# a comment
print('more code')

我们可以摘录用“%”标记的注释:

# A Tutorial Introduction
## Getting Started
### The First Python Function
## Variables and Arithmetic Expressions

这是有效的 markdown 我们可以用 pandoc 是的。

再详细一点

假设您有一个文件“tests/files/some_file.txt”正在读取:

#######% % All About Me
#######% % Me
####### The above defines a pandoc markdown header.
####### This is more text that will not be extracted.
#######% **This** is an example of a markdown paragraph: markdown
#######% recognizes only six levels of heading, so we use seven or
#######% more levels to mark "normal" text.
#######% Here you can use the full markdown
#######% [syntax](http://daringfireball.net/projects/markdown/syntax).
#######% *Note* the trailing line: markdown needs an empty line to end
#######% a paragraph.
#######%

#% A section
##% A subsection
### Not a subsubsection but a plain comment.
############% Another markdown paragraph.
############%
####### More text that will not be extracted.

然后通过

importexcerptsfile_name='tests/files/some_file.txt'withopen(file_name)asinfile:lines=infile.readlines()excerpted=excerpts.excerpt(lines=lines,comment_character="#",magic_character="%")
print(''.join(str(p)forpinexcerpted))

给出

% All About Me
% Me
**This** is an example of a markdown paragraph: markdown
recognizes only six levels of heading, so we use seven or
more levels to mark "normal" text.
Here you can use the full markdown
[syntax](http://daringfireball.net/projects/markdown/syntax).
*Note* the trailing line: markdown needs an empty line to end
a paragraph.

# A section
## A subsection
Another markdown paragraph.

又是有效的 markdown 对于 pandoc 是的。

使用文件

如果要从文件中摘录并对结果运行pandoc,可以使用

excerpts.excerpts(file_name=file_name,comment_character="#",magic_character="%",output_path="output",run_pandoc=True,pandoc_formats="html")

产生 this file.

命令行界面

摘要有一个命令行接口,您可以从 操作系统的命令行,而不是python3:

usage: excerpts [-h] [-O OUTPUT_PATH] [-o POSTFIX] [-e PREFIX]
                [-c COMMENT_CHARACTER] [-m MAGIC_CHARACTER] [-v] [-x]
[-p]
                [-n] [-l] [--no-latex] [--formats PANDOC_FORMATS]
[--no-pep8]
                file

excerpt markdown-style comments from a file to markdown and

PEP8

PEP8要求“块注释的每一行以一个和一个空格开头”。 摘要通过删除一个注释字符来满足此要求 后面是一个空格和一系列注释字符。 如果需要禁用此行为,可以将allow_pep8设置为false。

要求

节选需要Python3。

安装

尝试
pip3安装git+git://gitlab.com/fvafrcu/execpts–升级–用户

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java OpenShift的齿轮特性   java如何在Liferay站点的每个页面上放置公司地址和电话?   java确定整数数组中是否存在一个子集,在两个条件下求和到给定的目标值   序列化为什么java中的serialVersionUID必须是静态的、最终的、长类型的?   java响应返回null   java注入接口实现Quarkus   java我不明白为什么第二次排序的运行时间比第一次慢?   (Java)显示图像的最佳方式?   java Android应用程序因添加布局而崩溃   java如何在运行时获取泛型变量的类   java Selenium web驱动程序:无效的选择器:*:WebKitFullScreenSentor   Spring中的java注入值始终为空   Eclipse中带有TestNG插件的@BeforeSuite和@AfterSuite的java问题   使用trycatch块、filewriter和printwriter在java中创建自定义类   如何在Java 安卓上绘制相交的两条线