what do %(xyz)s representation mean in python
What are these representation in python and how to use. My guess is it is used for data validation but never able to use it.
%(name)s
%(levelno)s
%(levelname)s
%(pathname)s开发者_运维百科
%(process)d
etc..
This is string formatting using keys:
>>> d = {"answer": 42}
>>> "the answer is %(answer)d" % d
'the answer is 42'
It's formatting a string, by picking values from a dictionary:
test = { "foo": 48, "bar": 4711, "hello": "yes" }
print "%(foo)d %(bar)d and %(hello)s" % test
prints:
48 4711 and yes
精彩评论