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

Discussion in 'Python' started by Fredrik Lundh, Jun 27, 2003.

  1. 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>
    Fredrik Lundh, Jun 27, 2003
    #1
    1. Advertising

  2. Fredrik Lundh

    Troy Melhase Guest

    >> 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
    Troy Melhase, Jun 27, 2003
    #2
    1. Advertising

  3. 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
    Skip Montanaro, Jun 27, 2003
    #3
  4. [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
    =?iso-8859-1?q?Fran=E7ois_Pinard?=, Jun 27, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mike Strauss

    Activating JavaScript from C#

    Mike Strauss, Dec 19, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    5,932
    Elton Wang
    Dec 20, 2004
  2. Robert Rotstein

    activating a SOAP extension from the client

    Robert Rotstein, Jan 10, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    428
    Robert Rotstein
    Jan 10, 2006
  3. Robert Rotstein

    activating a SOAP extension from a client

    Robert Rotstein, Jan 10, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    315
    Robert Rotstein
    Jan 10, 2006
  4. =?iso-8859-1?q?Fran=E7ois_Pinard?=

    Activating `-i' from inside a script?

    =?iso-8859-1?q?Fran=E7ois_Pinard?=, Jun 27, 2003, in forum: Python
    Replies:
    2
    Views:
    628
    Fernando Perez
    Jul 1, 2003
  5. Bob Gailer
    Replies:
    0
    Views:
    622
    Bob Gailer
    Jun 27, 2003
Loading...

Share This Page