Python Forum

Full Version: Stopping a parent function from a nested function?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Here's an example:
# I want to stop function parent() from function child().

def parent():
  def child():
    print('A')
    returnparent # Or something along the lines
  child()
  print('B')
parent()
Wanted output:
Output:
A
Actual output(without the returnparent):
Output:
A B
Is there a statement or function that serves this purpose?
This is similar to this question. There is no such statement in Python but you can raise an exception. Using the solution that I posted in the other thread, you could write this to achieve the same effect
class parent(returnable):
    def main(self):
        self.child()
        print('B')

    def child(self):
        print('A')
        self.return_()
parent()