相关疑难解决方法(0)

如果只有功能B需要功能A应该在B内定义A?

简单的例子.两种方法,一种叫另一种方法:

def method_a(arg):
    some_data = method_b(arg)

def method_b(arg):
    return some_data
Run Code Online (Sandbox Code Playgroud)

在Python中,我们可以def在另一个内部声明def.因此,如果method_b需要并且仅从中调用method_a,我应该method_b在内部声明method_a吗?像这样 :

def method_a(arg):

    def method_b(arg):
        return some_data

    some_data = method_b
Run Code Online (Sandbox Code Playgroud)

或者我应该避免这样做?

python coding-style

140
推荐指数
8
解决办法
24万
查看次数

标签 统计

coding-style ×1

python ×1