Sunil Kumar
Sunil Kumar

Reputation: 1349

How to access a function defined globaly outside of the class

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?

Upvotes: 0

Views: 68

Answers (1)

alecxe
alecxe

Reputation: 473893

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?

Upvotes: 1

Related Questions