Let's say that a function A
is required only by function B
, should A be defined inside B?
Simple example. Two methods, one called from another:
def method_a(arg):
some_data = method_b(arg)
def method_b(arg):
return some_data
In Python we can declare def
inside another def
. So, if method_b
is required for and called only from method_a
, should I declare method_b
inside method_a
? like this :
def method_a(arg):
def method_b(arg):
return some_data
some_data = method_b(arg)
Or should I avoid doing this?
Is this what you were looking for? It's called a closure.