在按位置替换参数时,逆转Python的str.format过程的最优雅方法是什么?
例如,以下内容:
textpattern = 'Please move {0} to {1}'
mystring = 'Please move a to b'deformat函数:
mystring.deformat(textpattern)将返回列表['a', 'b']。变量textpattern由用户输入,然后动态地从DB中获取。
我发现的最接近的东西是a question about scnaf in Python,但这略有不同。
发布于 2016-03-20 12:50:31
您正在寻找包parse,它被描述为:()与format()相反。
https://stackoverflow.com/questions/36113875
复制相似问题