python中的这些表示形式以及如何使用。我的猜测是它用于数据验证但从未能够使用它。
%(name)s
%(levelno)s
%(levelname)s
%(pathname)s
%(process)d
etc..
答案 0 :(得分:6)
这是string formatting using keys:
>>> d = {"answer": 42}
>>> "the answer is %(answer)d" % d
'the answer is 42'
答案 1 :(得分:2)
通过从字典中选择值来格式化字符串:
test = { "foo": 48, "bar": 4711, "hello": "yes" }
print "%(foo)d %(bar)d and %(hello)s" % test
打印:
48 4711 and yes