Python にも sprintf 相当があったのね

% 演算子

>>> "<%.*s>" % (3, "hoge")
'<hog>'
>>> "<%*d>" % (6, 123)
'<   123>'
>>> "<%2$d %1$d>" % (123, 456)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: unsupported format character '$' (0x24) at index 3
>>> "<%s><%d><%f>" % ("hoge",123,3.14)
'<hoge><123><3.140000>'
>>> "<%s><%d><%f>" % (123,3.14,"hoge")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: float argument required
>>> '<%d><%u><%x><%o>' % ((-2147483648,)*4)
'<-2147483648><-2147483648><-80000000><-20000000000>'
>>> '<%f><%e><%g>' % ((3.14,)*3)
'<3.140000><3.140000e+000><3.14>'
>>> '<>' % None
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: not all arguments converted during string formatting
>>> '<%d><%s>' % 123
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: not enough arguments for format string
>>> '<%#.3o>' % 10
'<012>'
>>> '<% #+-0*.*T>' % (0,0,None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: unsupported format character 'T' (0x54) at index 10
>>> '<%#8.5x>' % 255
'< 0x000ff>'
>>> '<%p>' % None
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: unsupported format character 'p' (0x70) at index 2