Python Forum
Stopping a parent function from a nested function?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Stopping a parent function from a nested function?
#1
Question 
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?
Reply
#2
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()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  The function of double underscore back and front in a class function name? Pedroski55 9 563 Feb-19-2024, 03:51 PM
Last Post: deanhystad
  nested function return MHGhonaim 2 562 Oct-02-2023, 09:21 AM
Last Post: deanhystad
  return vs. print in nested function example Mark17 4 1,674 Jan-04-2022, 06:02 PM
Last Post: jefsummers
  Exit function from nested function based on user input Turtle 5 2,858 Oct-10-2021, 12:55 AM
Last Post: Turtle
Question exiting the outer function from the inner function banidjamali 3 3,466 Feb-27-2021, 09:47 AM
Last Post: banidjamali
  Getting parent variables in nested functions wallgraffiti 1 2,100 Jan-30-2021, 03:53 PM
Last Post: buran
  Nested function problem chipx 8 3,414 Oct-21-2020, 11:56 PM
Last Post: jefsummers
  Passing argument from top-level function to embedded function JaneTan 2 2,204 Oct-15-2020, 03:50 PM
Last Post: deanhystad
  accessing a second level nested function varsh 3 2,437 Aug-13-2020, 06:57 AM
Last Post: varsh
  stopping number conversion before end Skaperen 6 2,942 Jul-12-2020, 09:22 AM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020