相关疑难解决方法(0)

Python:使用"..%(var)s .."%locals()是一个好习惯吗?

我发现了这种模式(或反模式),我对它非常满意.

我觉得它非常敏捷:

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匹配位置.

你喜欢它吗?你会/你会用它吗?是/否,请解释.

python string design-patterns anti-patterns

70
推荐指数
6
解决办法
2万
查看次数

标签 统计

anti-patterns ×1

design-patterns ×1

python ×1

string ×1