Detect PythonWin?

Martin Bless mb at muenster.de
Sat Aug 2 05:20:52 EDT 2003


[Brett g Porter:]

>Is there a subtle reason that you can't pass the arguments using the 
>"Arguments" field on the PythonWin "Run Script" dialog?

(1) Yes, there is, very subtle =:-)
[shame ON] I simply have overlooked the argument field since that long
- unbelievable. [shame OFF] Got that very much used to pressing ctrl+r
or F10 that I never really noticed the dialog anymore. Once you're
blind, ...

(2) But: I need the PythonWin detector as well

- to skip code that doesn't run (well) in PythonWin (e. g. low level
stuff)

- to conditionally set hardcoded breakpoints for analyses

- to turn off verbose output, for instance a counter which is
displayed in a single line of the command window. Now I can do

#untested
cnt = 0
for item in items:
    cnt += 1
    if sys.modules.has_key('pywin'):
        pass
        "or display in a message box. How is that done???"
    else:
        print cnt,  # stay in line
        msvcrt.putchr('\r')  # carriage return to beginning of line

(3) Thank you all for answering. Writing either

if 'pywin' in dir():
    pass

or, I think, better:

CHECKPYWIN = True
...
import sys
if CHECKPYWIN and sys.modules.has_key('pywin'):
    "work"

is exactly what I need. Seems robust enough. And additionally, to be
on the safe side, I will set the 'constant' CHECKPYWIN to False once
testing is done, leaving no ambiguities.

(4) I'd love to see this issue addressed somewhere in the PythonWin
helpfiles!?

thank you all

Martin





More information about the Python-list mailing list