Answer the question
In order to leave comments, you need to log in
How to call a function that is in the body of another function?
Let's say I have a program:
def foo():
# code
def foo_in_foo():
# code
# что-то вроде того:
foo.foo_in_foo()
Answer the question
In order to leave comments, you need to log in
No way. You can't access a function's local variable, which is essentially the same thing.
Why not, you can pull it out through a global variable.
Just don't remember this approach, it's terrible code:
>>> def foo():
... print('executing foo()')
... def foo_in_foo():
... print('executing foo_in_foo()')
... global inner
... inner = foo_in_foo
...
>>> foo()
executing foo()
>>> inner
<function foo.<locals>.foo_in_foo at 0x07BBD1E0>
>>> inner()
executing foo_in_foo()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question