john gruber的titlecase.pl的python端口
titlecase的Python项目详细描述
此筛选器将所有单词更改为标题大写,并尝试使 关于输入中的a/an/之类的小单词。
未封顶的“小词”名单来自纽约 时代风格手册,加上其他一些像“V”和“V”。
这是Stuart Colville’s titlecase.py的复活, 又是John Gruber’s titlecase.pl的端口。
应指示问题、更新、请求等 to github。
安装
最简单的方法是简单地使用pip:
(sudo) pip install titlecase
用法
titleCase只提供一个功能,很简单:
>>>fromtitlecaseimporttitlecase>>>titlecase('a thing')'A Thing'
还可以提供回调函数,该函数将为每个单词调用:
>>>defabbreviations(word,**kwargs):...ifword.upper()in('TCP','UDP'):...returnword.upper()...>>>titlecase.titlecase('a simple tcp and udp wrapper',callback=abbreviations)'A Simple TCP and UDP Wrapper'
回调函数提供了一个all_caps关键字参数,指示 整行文字是否全部大写。从返回None 回调函数将允许titleCase正常处理单词。
命令行用法
titlecase还提供命令行实用程序titlecase:
$titlecasemakemeatitleMakeMeaTitle$echo"Can pipe and/or whatever else"|titlecaseCanPipeand/orWhateverElse# Or read/write files:$titlecase-finfile-ooutfile