Search code examples
pythonclasscall

How to stop a class halfway, to run the next class, and how to do so?


I searched on the internet and couldn't find a solution. Please help. Let's say...

class A(self):
    def __init__ (self):
        """one chunk of code here"""

    if (condition met):
        print 'access granted'
        """I want to stop the code here and ask it to run class B, instead of just one method from class B"""
    else:
        print 'Stop process'
        break

class B(self):
    def __init__ (self):
        """one more chunk of codes here"""

Is this possible? (pardon my mess of codes)


Solution

  • Your if condition code will run only once when you run that script. Whenever you create an instance of a class, only __init__ function is run. As interjay mentioned, you don't run a class, you run functions.