7
Python:使用“ ..%(var)s ..”%locals()是一种好习惯吗?
我发现了这种模式(或反模式),对此我感到非常满意。 我觉得它非常敏捷: def example(): age = ... name = ... print "hello %(name)s you are %(age)s years old" % locals() 有时我用它的表弟: def example2(obj): print "The file at %(path)s has %(length)s bytes" % obj.__dict__ 我不需要创建人为的元组并计算参数并将%s匹配位置保留在元组中。 你喜欢它吗?您会/会使用它吗?是/否,请解释。