使用当前作用域中的名称格式化字符串。

ScopeFormatter的Python项目详细描述


scopeformatter允许对名称使用python的字符串格式 从当前范围绘制,类似于变量插值 在ruby和perl等语言中发现。

Examples

>>> from scopeformatter import F
>>> greeting = 'Hello'
>>> def greet(name):
...     return F('{greeting}, {name}!')
>>> greet('world')
'Hello, world!'

接受位置参数和关键字参数:

>>> F('{greeting} {0} times, {name}!', len(greeting), name='world')
'Hello 5 times, world!'

Requirements

堆栈检查需要一个python vm,它提供 sys._getframe(),例如cpython。

Limitations

将找不到封闭作用域中的非全局名称,除非 它们在本地范围内被引用。

>>> def outer():
...     non_local = 'non-local'
...     def inner():
...         return F('{non_local} is not referenced locally')
...     return inner()
>>> outer()
Traceback (most recent call last):
    ...
KeyError: 'non_local'
>>> def outer():
...     non_local = 'non-local'
...     def inner():
...         non_local
...         return F('{non_local} is referenced locally')
...     return inner()
>>> outer()
'non-local is referenced locally'

History

1.0.3 – 2009 Oct 22

  • 将历史记录添加到项目页。
  • 添加了其他文档文件。

1.0.2 – 2009 Oct 22

  • 重新组织元数据。
  • 删除了对setuptools和nose的依赖关系。

1.0.1 – 2009 Oct 3

  • 对元数据进行了少量添加。

1.0 – 2009 Sept 25

  • 初次发布。

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

推荐PyPI第三方库


热门话题
java操作数组上的字符串   java JAXB内容未实例化   图形在Java中如何绘制垂直居中的字符串?   java Apache Ant:使用Junit时出现NoClassDefFoundError   java无法从服务器上运行perl脚本   如何在java中沿树进行预排序遍历,并打印0和1以对应每个节点上的特定字符?   java如何创建。p12文件?   java线程访问无效   java只匹配命名空间中的XML节点,而不知道NS前缀   从java获取2d arraylist元素   数组Java动态集合对象   java Xpath通过通配符或布尔运算查找以相同名称开头的节点?   java注释元素类型   java在中看不到Super()。反编译后的类文件