Python Forum
Pausing and returning to function?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pausing and returning to function?
#1
The basic idea I have is something like this, but with actual python builtins:
def somefunc():
    print('Something')
    pause
    print('Other Thing')

somefunc()
somefunc()
Expected output:
Output:
Someting Other Thing
I used to think that yield could do this, but as I have found out, yield simply makes a generator. Is there a built in solution, or some other way to do this?
Reply
#2
You have to have state stored somewhere. A generator is a normal way to do that, but does mean you have to call the iterator that it returns to get the data, not the function that creates the generator.

def somefunc():
    yield 'Something'
    yield 'Other Thing'


iterator = somefunc()
print(next(iterator))
print(next(iterator))
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Why my function is returning None? PauloDAS 6 1,742 Jul-17-2022, 11:17 PM
Last Post: Skaperen
  Why is the function returning None for a * b instead of number? omm 10 4,282 Nov-05-2020, 01:17 PM
Last Post: omm
  Having hard time understanding the function self-returning itself twice jagasrik 2 2,473 Aug-15-2020, 08:50 PM
Last Post: deanhystad
  Returning Value from Function with Trackbars vicpylon 3 2,047 May-24-2020, 11:28 PM
Last Post: bowlofred
  Nested Recursive Function not Returning Etotheitau 2 2,248 May-09-2020, 06:09 PM
Last Post: Etotheitau
  Slide show with mouse click pausing aantono 1 2,189 Jan-28-2020, 04:25 AM
Last Post: Larz60+
  Function not returning correct value ActualNoob 3 2,675 Jan-11-2019, 12:35 AM
Last Post: stullis
  Pausing a running process? MuntyScruntfundle 2 7,221 Nov-14-2018, 05:14 PM
Last Post: woooee
  Function not returning expected value Euqinu 4 3,464 Sep-10-2018, 12:48 PM
Last Post: Euqinu
  Pausing a Script malonn 4 3,803 Aug-04-2018, 07:58 PM
Last Post: malonn

Forum Jump:

User Panel Messages

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