路径名的模板和宏扩展。

tmep的Python项目详细描述


This package on the Python Package IndexContinuous integrationDocumentation Status

tmep

路径名的模板和宏扩展。

安装

来自Github
git clone https://github.com/Josef-Friedrich/tmep.git
cd tmep
python setup.py install

来自PYPI

pip install tmep
easy_install tmep

使用量

>>>importtmep>>>template='$prename $lastname'>>>values={'prename':'Franz','lastname':'Schubert'}>>>out=tmep.parse(template,values)>>>print(out)FranzSchubert

这个模块实现了一个基于标准pep的字符串格式化程序。 292字符串。模板类用函数调用扩展。变量,作为 with string.template,用$表示,函数用分隔符分隔 与百分比。

此模块假设所有内容都是Unicode的:模板和 替代值。不支持bytestrings。另外,模板 总是像标准中的safe_substitute方法一样 库:未知符号保持不变。

这有点像是一个小小的,可怕的模板退化 引擎像Jinja2或者胡子。

发展

测试
tox

发布新版本
git tag 1.1.1
git push --tags
python setup.py sdist upload

包文档

包文档托管在 readthedocs

生成包文档:

python setup.py build_sphinx

功能

alpha
-----

%alpha{text}
    This function first ASCIIfies the given text, then all non alphabet
    characters are replaced with whitespaces.

alphanum
--------

%alphanum{text}
    This function first ASCIIfies the given text, then all non alpanumeric
    characters are replaced with whitespaces.

asciify
-------

%asciify{text}
    Translate non-ASCII characters to their ASCII equivalents. For
    example, “café” becomes “cafe”. Uses the mapping provided by the
    unidecode module.

delchars
--------

%delchars{text,chars}
    Delete every single character of “chars“ in “text”.

deldupchars
-----------

%deldupchars{text,chars}
    Search for duplicate characters and replace with only one occurrance
    of this characters.

first
-----

%first{text} or %first{text,count,skip} or
%first{text,count,skip,sep,join}
    Returns the first item, separated by ; . You can use
    %first{text,count,skip}, where count is the number of items (default
    1) and skip is number to skip (default 0). You can also use
    %first{text,count,skip,sep,join} where sep is the separator, like ; or
    / and join is the text to concatenate the items.

if
--

%if{condition,truetext} or %if{condition,truetext,falsetext}
    If condition is nonempty (or nonzero, if it’s a number), then returns
    the second argument. Otherwise, returns the third argument if
    specified (or nothing if falsetext is left off).

ifdef
-----

%ifdef{field}, %ifdef{field,text} or %ifdef{field,text,falsetext}
    If field exists, then return truetext or field (default). Otherwise,
    returns falsetext. The field should be entered without $.

ifdefempty
----------

%ifdefempty{field,text} or %ifdefempty{field,text,falsetext}
    If field exists and is empty, then return truetext. Otherwise, returns
    falsetext. The field should be entered without $.

ifdefnotempty
-------------

%ifdefnotempty{field,text} or %ifdefnotempty{field,text,falsetext}
    If field is not empty, then return truetext. Otherwise, returns
    falsetext. The field should be entered without $.

initial
-------

%initial{text}
    Get the first character of a text in lowercase. The text is converted
    to ASCII. All non word characters are erased.

left
----

%left{text,n}
    Return the first “n” characters of “text”.

lower
-----

%lower{text}
    Convert “text” to lowercase.

nowhitespace
------------

%nowhitespace{text,replace}
    Replace all whitespace characters with replace. By default: a dash (-)
    %nowhitespace{$track,_}

num
---

%num{number,count}
    Pad decimal number with leading zeros.
    %num{$track,3}

replchars
---------

%replchars{text,chars,replace}
    Replace the characters “chars” in “text” with “replace”.
    %replchars{text,ex,-} > t--t

right
-----

%right{text,n}
    Return the last “n” characters of “text”.

sanitize
--------

%sanitize{text}
    Delete in most file systems not allowed characters.

shorten
-------

%shorten{text} or %shorten{text,max_size}
    Shorten “text” on word boundarys.
    %shorten{$title,32}

time
----

%time{date_time,format,curformat}
    Return the date and time in any format accepted by strftime. For
    example, to get the year some music was added to your library, use
    %time{$added,%Y}.

title
-----

%title{text}
    Convert “text” to Title Case.

upper
-----

%upper{text}
    Convert “text” to UPPERCASE.

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

推荐PyPI第三方库


热门话题
java不可访问配置设计   在java中使用json就像在javascript中一样   java如何屏蔽Android 4.0主密钥   java为什么clickable的预期条件不执行click()?   Azure事件中心:Kafka消费者在java中不轮询任何内容   javajaxb和enum实现接口   java如何在标记下添加ProgressBar和按钮   java如何为对象实现arrayList   使用多重匹配重载java构造方法重载   java使用for循环和if语句搜索帐户   java JPanel在JPanel中添加了顶部填充   IntelliJ将Java项目/模块转换为Maven项目/模块   java如何迭代arraylist中的arraylist   自定义类的java“找不到符号”错误