【发布时间】:2016-03-20 12:47:40
【问题描述】:
在按位置替换参数时,逆转 Python 的 str.format 过程的最优雅的方法是什么?
例如以下
textpattern = 'Please move {0} to {1}'
mystring = 'Please move a to b'
deformat 函数:
mystring.deformat(textpattern)
将返回列表['a', 'b']。变量textpattern 正在由用户输入,然后从数据库中动态获取。
我找到的最接近的是a question about scnaf in Python,但略有不同。
【问题讨论】:
标签: python-2.7 text-extraction string.format