0

I have 2 scripts. Main.py and module1.py.

Module1.py

class classA():
    def method1(self):
        self.c=a+b
        ....
        ....
    def method2():
        ....
class classB():
    ....
class classC():
    ....

Main.py

import module1
print module1.classA.c    

I am trying to access the variable c from module1.py classA in the main.py But when i run main.py, it gave me error saying "c is not defined".What is the correct way to do it? i have tried _builtin_ as well but it gave me the same error.

1 Answer 1

3

You did not call the function, thus self.c would never have been created. Also, create an instance of the class:

import module1
myinst = module1.classA()
myinst.method1()
print myinst.c
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.