[Python-Dev] Re: Activating `-i' from inside a script?

Thomas Heller theller@python.net
2003年6月27日 14:06:42 +0200


Skip Montanaro <skip@pobox.com> writes:
> On c.l.py someone asked about forcing a tailend interactive shell from
> within the program. Try Melhase proposed:
>> import os
>> if __name__ == '__main__':
> discrepancy = True
> if discrepancy:
> os.environ['PYTHONINSPECT'] = "why yes, i'd like that"
>> but observed that it doesn't work because the environment variable is only
> checked at program start.
>> This change to Modules/main.c makes the above work:
[...]
>> Any chance this could be squeezed in? It seems rather elegant:
>> try:
> something which fails
> except:
> os.environ["PYTHONINSPECT"] = 1
> raise
>> (I know we're at beta1, and the programmer could re-run with -i. But
> still...)
>
For a different approach to the same (?) problem see
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65287
Thomas

AltStyle によって変換されたページ (->オリジナル) /