Function to terminate while loop in python? -
i create function keep_running define based on input either sensitive time had been running or number of iterations. can't seem come pythonic way iterations without decrementing counter outside of function, e.g.:
def keep_running(ttl): return ttl > 0 ttl = 1 while keep_running(ttl): do_stuff() ttl -= 1 is there better way this, preferably within function keep_running?
the best way manage state inside class. initialize object loop_context ttl value, , loop condition loop_context.keep_running().
Comments
Post a Comment