0

In the program bellow, is it possible to access method AA by only calling method B? Perhaps something similar to declearing variables global?

def A():
    print("This is method A.")
    def AA():
        print("This is method AA, which is inside method A.")

def B():
    print("This is method B.")
    AA()

B()
Heikki
  • 341
  • 2
  • 18

1 Answers1

0

A function defined within a function is by its nature not accessible globally. This is normally only done when you want encapsulation or if the outer function is generating and returning an inner function (like a factory function). If you need access to that function you can either return it as the result of function A, call function A and add a call to function AA within A, or define AA outside of A.

NendoTaka
  • 1,224
  • 8
  • 14