我发现了这种模式(或反模式),我对它非常满意.
我觉得它非常敏捷:
def example():
age = ...
name = ...
print "hello %(name)s you are %(age)s years old" % locals()
Run Code Online (Sandbox Code Playgroud)
有时候我会用它的堂兄:
def example2(obj):
print "The file at %(path)s has %(length)s bytes" % obj.__dict__
Run Code Online (Sandbox Code Playgroud)
我不需要创建一个人工元组并计算参数并保持元组内的%s匹配位置.
你喜欢它吗?你会/你会用它吗?是/否,请解释.