How do I tell if I'm running in the PyWin interpreter?

Charles Krug cdkrug at aol.com
Fri Jan 27 22:05:43 EST 2006


Here's the deal:

I've a dead-simple command-line program I'm using to test things that I
can't (for various reasons) test in the IDE.

Here's a do-nothing subset that shows the idea:

# insanely simply command interpreter
import Commands
import sys

myPrompt = '$> '

# Raw Input doesn't QUITE do what I want in Python Win.
while True:
    try:
        args = raw_input(myPrompt).strip().split()
    except EOFError:
        break

    cmd = args[0]
    print '>%s<' % cmd
    print args

As the comment says, when I run this under Python Win, I get an (pretty
sure) Tkinter interface, not a command line, and I don't get my
EOFError when I expect to.

This is something I occasionally need in my Swiss Army Knife.  Not
often, but when I need something like this, I need something like THIS
pretty badly, and sometimes I need to run it under PyWin (and under
Linux, Unix, Solaris, and anything else you might name and a few things
I bet you couldn't).

Is there a way to detect that I'm running the the PyWin interpreter so
that I can bypass its raw_input behavior?

Is there a simpler way to do this?

I recall some sample code that did something very much like this (define
a small set of callbacks and execute them from a command-like interface)
but I can't seem to lay my hands on the example.

Thanx


Charles



More information about the Python-list mailing list