Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Activating `-i' from inside a script?

Reply
Thread Tools

Re: Activating `-i' from inside a script?

 
 
Fredrik Lundh
Guest
Posts: n/a
 
      06-27-2003
François Pinard wrote:
> Is there a way for a script to activate the effect of the `-i' option, that
> is, to force interactive mode once `__main__' has run? For one application,
> I would like that if the application discovers some data discrepancy or
> failure (not a Python error) and only then, and if the application was also
> started from a tty, it gives the user to interactively explore, using
> Python, the context that was built while the run was going.


something like this might work:

if discrepancy and sys.stdin.isatty():
import code; code.interact(local=globals())

</F>




 
Reply With Quote
 
 
 
 
Troy Melhase
Guest
Posts: n/a
 
      06-27-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

 
Reply With Quote
 
 
 
 
Skip Montanaro
Guest
Posts: n/a
 
      06-27-2003

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

Troy> import os

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

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

The slight, obvious rearrangement to Modules/main.c seems to work. I'll
propose it on python-dev.

Skip

 
Reply With Quote
 
=?iso-8859-1?q?Fran=E7ois_Pinard?=
Guest
Posts: n/a
 
      06-27-2003
[Troy Melhase]

> 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?


It would be nice if the Python crew was willing to see this as a bug. A
program might also delete PYTHONINSPECT if it feels shy to get naked.

--
François Pinard http://www.iro.umontreal.ca/~pinard

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Activating both A + G Wireless Channels =?Utf-8?B?YnJlbnRyb21lcm8=?= Wireless Networking 2 11-02-2005 01:34 AM
2732 Activating expired training material on retail version of VPC =?Utf-8?B?c3BpbmZpeGxpeg==?= Microsoft Certification 1 09-01-2005 02:56 PM
activating encryptiong causes device to be hidden from workgroup Keyser Wireless Networking 1 05-10-2005 02:36 PM
Activating `-i' from inside a script? =?iso-8859-1?q?Fran=E7ois_Pinard?= Python 2 07-01-2003 01:46 AM
Re: Activating `-i' from inside a script? Bob Gailer Python 0 06-27-2003 03:07 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57