Reputation: 3116
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..
Upvotes: 2
Views: 169
Reputation: 400019
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
Upvotes: 2
Reputation: 14212
This is string formatting using keys:
>>> d = {"answer": 42}
>>> "the answer is %(answer)d" % d
'the answer is 42'
Upvotes: 6