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
  • 100,903
  • 11
  • 120
  • 169
Sunil Kumar
  • 1,349
  • 3
  • 14
  • 25

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
  • 462,703
  • 120
  • 1,088
  • 1,195