exit to interpreter?

Mel Wilson mwilson at the-wire.com
Fri Mar 23 15:41:55 EDT 2007


belinda thom wrote:
> On Mar 23, 2007, at 11:04 AM, kyosohma at gmail.com wrote:
> 
>> On Mar 23, 12:52 pm, belinda thom <b... at cs.hmc.edu> wrote:
>>> Hi,
>>>
>>> I'm writing a function that polls the user for keyboard input,
>>> looping until it has determined that the user has entered a valid
>>> string of characters, in which case it returns that string so it can
>>> be processed up the call stack. My problem is this. I'd also like it
>>> to handle a special string (e.g. 'quit'), in which case control
>>> should return to the Python command line as opposed to returning the
>>> string up the call stack.
>>>
>>> sys.exit seemed like a good choice, but it exits the python  
>>> interpreter.
>>>
>>> I could use an exception for this purpose, but was wondering if
>>> there's a better way?

A custom-defined exception is probably the best way to jump out of a 
stack of nested calls.


	Mel.




More information about the Python-list mailing list