Activating `-i' from inside a script?

Troy Melhase troy at gci.net
Fri Jun 27 08:09:44 CEST 2003


>> Is there a way for a script to activate the effect of the `-i' option,
> something like this might work:
> 
> if discrepancy and sys.stdin.isatty():
>     import code; code.interact(local=globals())

François, Fredrik:

I thought this would work, but it doesn't:

import os

if __name__ == '__main__':
    discrepancy = True
    if discrepancy:
        os.environ['PYTHONINSPECT'] = "why yes, i'd like that"


A quick read of Modules/main.c shows that the environment variable is
checked at program start, not at end.  Maybe this is a bug?

-troy





More information about the Python-list mailing list