Dynamically Cause A Function To Return
rosuav at gmail.com
Tue Sep 20 14:35:24 EDT 2011
On Tue, Sep 20, 2011 at 9:13 AM, Jordan Evans <mindwalkernine at gmail.com> wrote:
> I want dynamically place the 'return' statement in a function via user input
> or achieve the same through some other means. If some other means, the user
> must be able initiate this at runtime during a raw_input(). This is what I
> have so far, this would be an awesome command line debugging tool if I can
> get it to work.
Not entirely sure what you're trying to accomplish here. You want to
pepper your code with calls to b() and then have the user be able to
abort the function from there? If so, I can think of two ways:
1) Have b() raise an exception, which you catch at a high level.
That'd unwind the stack all the way to the top, which may or may not
be what you want. Pretty easy to do though.
2) Pepper your code with:
if b(): return
and then have b return 0 normally and 1 when the user asks to abort.
This isn't truly an interactive debugger, though it does potentially
have much value.
More information about the Python-list