python -i (interactive environment)

Steve Holden steve at holdenweb.com
Mon Mar 7 14:43:49 EST 2005


Michael Hoffman wrote:
> Joe wrote:
> 
>> I want the script to decide whether to fall back to the interactive 
>> prompt. You solution makes it ALWAYS fall back to the interactive prompt.
> 
> 
> Actually, using sys.exit() means the program can exit even if python -i
> is used.
> 
> You can use:
> 
> import code
> code.interact()
> 
> which emulates the interactive prompt.

Unfortunately it does so in an entirely new namespace, thereby losing 
the advantage of -i - namely, that you can investigate the program's 
namespace after it's terminated.

regards
  Steve




More information about the Python-list mailing list