0

I am new to Python, and I am facing a problem:

def a():  ....

class b :   
    def c():
         x=a()

My function a is defined outside of the class, and I need it to access inside the class in function c. How should I do this?

Blckknght
  • 93,977
  • 11
  • 112
  • 159
Sunil Kumar
  • 1,278
  • 3
  • 14
  • 24

1 Answers1

1

Just call it using a(), it's available through the global module scope:

def a():
    return "test"


class b:
    def c(self):
        x = a()
        print x

b().c()  # prints "test"

Also see this thread: Short Description of the Scoping Rules?

Community
  • 1
  • 1
alecxe
  • 441,113
  • 110
  • 1,021
  • 1,148