将旧式的 %-style 格式字符串转换为新的 {}-style
项目描述
一个Python库,用于将旧式的 % 样式格式字符串转换为新的 {} 样式。
>>> import formatist
>>> greeting = "Hello %(name)s. It's %(temp).1f C"
>>> print(greeting % {'name': 'Alice', 'temp': 23.45678})
Hello Alice. It's 23.5 C
>>> greeting2 = formatist.convert(greeting)
>>> print(greeting2)
Hello {name!s:}. It's {temp:>.1f} C
>>> print(greeting2.format(name='Alice', temp=23.45678))
Hello Alice. It's 23.5 C