开发者

Passing kwargs into a python string for rendering rather then using %s/%d...etc

About a week ago I saw a script using kwargs i开发者_如何转开发n the string template. Unfortunately I can't re-find that script so I thought I'd ask to see if anyone knows of a way that I can pass kwargs into the string builder rather then just args.

Here is the desired result:

"""%name went to the store.""" %( name = John )

Naturally, this won't work and for the life of me I cannot remember the proper syntax.


"""%(name)s went to the store.""" % {"name": "John"}

or

"""%(name)s went to the store.""" % dict(name="John")
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜