, @admith , , python. , , () , .
? .
- , , Formatter - . python parse().. (, {test:6d}, - 6 ), , , parse, , format_spec conversion.
: , , .
import string
class myFormatter(string.Formatter):
def parse(self, fstring):
if fstring is None:
return
parts = fstring.split("}")
for part in parts:
if "{" in part:
literal, fieldname = part.split("{")
yield (literal, fieldname, None, None)
else:
yield (part, None, None, None)
:
>>> custom = myFormatter()
>>> custom.format("hello {test:1}", [], **{'test:1': 'world'})
'hello world'
:
print custom.vformat(templatestring, [], valuedict)