儿童文本操作助手。
kids.txt的Python项目详细描述
kids.txt是一个python库,提供用于管理文本的帮助程序。 这是“孩子”图书馆的一部分。
目前,这是一个非常简陋的包裹。
功能
使用kids.txt:
- python 2中还有一个indent/dedent/shorten命令。
- 您将能够wraptext保持段落分隔。
- 像ucfirst函数这样的次要助手。
- 使用udiff轻松生成两个字符串之间的统一差异。
安装
您不需要下载git版本的代码,因为kids.txtis PYPI上有。所以您应该能够运行:
pip install kids.txt
如果您下载了git源代码,那么可以添加install 当前版本通过传统:
python setup.py install
如果你没有git的来源但是想得到最新的 github的master或branch,您也可以:
pip install git+https://github.com/0k/kids.txt
或者甚至选择特定的修订(分支/标记/提交):
pip install git+https://github.com/0k/kids.txt@master
用法
缩进
您可以使用以下命令轻松缩进文本:
>>> from __future__ import print_function >>> from kids import txt >>> string = 'This is first line.\nThis is second line\n' >>> print(txt.indent(string, prefix="| ")) | This is first line. | This is second line |
dedent
您也可以输入文本:
>>> print(txt.dedent( ... '''This is a doc ... ... with fancy indentation, that should just work also. ... Without removing too much neither as: ... - more space.''')) This is a doc <BLANKLINE> with fancy indentation, that should just work also. Without removing too much neither as: - more space.
滑翔伞包裹
单独包装段落:
>>> string = 'This is first paragraph which is quite long don\'t you \ ... think ? Well, I think so.\n\nThis is second paragraph\n' >>> print(txt.paragraph_wrap(string)) This is first paragraph which is quite long don't you think ? Well, I think so. This is second paragraph Notice that that each paragraph has been wrapped separately.
ucfirst
此函数将返回给定字符串,其中第一个字符强制为 大写:
>>> txt.ucfirst('foo') 'Foo'
缩短
如果需要,此函数将把给定字符串截断为给定长度。会的 将最后两个字符替换为“..”表示截断:
>>> txt.shorten('fool', l=5) 'fool' >>> txt.shorten('supercalifragilisticexpialidocious', l=5) 'sup..'
udiff
显示到文本之间的统一差异:
>>> print(txt.udiff('a\n\nc', 'b\n\nc')) --- None +++ None @@ -1,3 +1,3 @@ -a +b <BLANKLINE> c <BLANKLINE>
贡献
欢迎提出任何建议或问题。非常欢迎推送请求, 请查看指南。
推送请求指南
你可以发送任何代码。我会自己研究并整合它 代码库,留下你作为作者。这个过程可能需要时间和 如果遵循以下指导原则,所需时间将更少:
- 用pep8或pylint检查代码。尽量坚持80列宽。
- 把你的承诺分开。
- 每次提交都应通过测试(以方便平分)
- 每个功能/错误修复提交都应该包含代码、测试, 还有医生。
- 先前的次要提交与排版或代码外观更改是 非常欢迎。它们应该在提交摘要中标记为 !minor。
- 提交消息应该遵循gitchangelog规则(检查git 登录以获取示例)
- 如果提交修复了问题或完成了 功能,请在摘要中提及。
如果你对指导方针有一些问题,这里没有回答, 请检查当前的git log,您可能会发现以前的提交 会告诉你如何处理你的问题。
更改日志
0.0.2(2015-02-04)
新的
- 添加了udiff以获得字符串的统一差异。[瓦伦丁实验室]
- 添加了ucfirst和shorten。[瓦伦丁实验室]
- 添加了一个dedent()函数。[瓦伦丁实验室]
修复
- indent将忽略first设置为空字符串。[瓦伦丁实验室]
0.0.1(2014-05-13)
- 第一次进口。[瓦伦丁实验室]