exit to interpreter?

belinda thom bthom at cs.hmc.edu
Tue Apr 3 02:05:39 EDT 2007


On Mar 24, 2007, at 4:30 AM, Dennis Lee Bieber wrote:

> On Fri, 23 Mar 2007 10:52:09 -0700, belinda thom <bthom at cs.hmc.edu>
> declaimed the following in comp.lang.python:
>
>> 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.
>>
> 	To the Python command line? That seems to imply that you started
> Python first, then imported the module with the function and  
> invoked it.

Yup

> 	Surely you don't expect this to be the normal operational mode for
> the program?

Its more for pedagogical purposes. I'm using Python in an undergrad  
prog class and I'd like students to be able to either enter one of a  
set of simple menu choices or quit to the interpreter. It should be  
command-based as opposed to GUI based. Hence the request.

> 	About the only way I know of to short circuit the calling stack
> requires using an exception -- and an exception handler at the top- 
> level
> (which, for your stated goal, probably has a "pass" for its body,  
> so the
> top-level will "exit" to the interpreter prompt).

This is similar to Mel's advice, which was what I'd expected but  
wanted to verify.

Thanks. For those who've been following this thread, this is the  
approach I took.

--b




More information about the Python-list mailing list