472,791 Members | 1,600 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,791 software developers and data experts.

Detect PythonWin?

IMHO PythonWin is great help in developing.

How can I do something like:

if detect("running on PythonWin"):
pass
# fake arguments ...
else:
"proceed normal"

?

Martin
Jul 18 '05 #1
7 2960
Martin Bless wants to know how to do:
if detect("running on PythonWin"):
pass
# fake arguments ...
else:
"proceed normal"


To see if you're on Windows,
import sys
sys.platform 'win32'


To see if the win32 extensions are installed

try:
import win32com # or another module in the extension
except ImportError:
print "Not installed"
else:
print "Installed!"

Andrew
da***@dalkescientific.com
Jul 18 '05 #2
[Andrew Dalke]:
To see if you're on Windows, [...]To see if the win32 extensions are installed


Ok,
but how can my script know it its running from inside PythonWin?

I often have the situation that while developing with PythonWin I have
to insert code like

if 1 and "developing in PythonWin":
sys.argv[1:] = ['fake', 'arguments']

Later on or when running the same script from the commandline I need
to disable this if statement. Nasty.

I'm looking for a predicate functions that will let my script know if
it's running from inside PythonWin. And the function shouldn't use
much time or resources if we are not in PythonWin.

Anybody knows?

Martin


Jul 18 '05 #3
Martin Bless
but how can my script know it its running from inside PythonWin?


I don't know if it is all that robust but performing 'dir()' from a
PythonWin Interactive Window shows an interesting 'pywin' symbol, so:

if 'pywin' in dir():
print 'PythonWin'

Seems to work.

Neil
Jul 18 '05 #4
Martin Bless wrote:

I often have the situation that while developing with PythonWin I have
to insert code like

if 1 and "developing in PythonWin":
sys.argv[1:] = ['fake', 'arguments']


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

That's always worked fine for me...

Jul 18 '05 #5
Martin Bless <m.*****@gmx.de> wrote in message news:<ej********************************@4ax.com>. ..
[Andrew Dalke]:
To see if you're on Windows,

[...]
To see if the win32 extensions are installed


Ok,
but how can my script know it its running from inside PythonWin?

I often have the situation that while developing with PythonWin I have
to insert code like

if 1 and "developing in PythonWin":
sys.argv[1:] = ['fake', 'arguments']

Later on or when running the same script from the commandline I need
to disable this if statement. Nasty.

I'm looking for a predicate functions that will let my script know if
it's running from inside PythonWin. And the function shouldn't use
much time or resources if we are not in PythonWin.

Anybody knows?

Martin

import sys
if sys.modules.has_key('pywin'): .... print "pythonwin running"
.... else:
.... print "pythonwin not running"
....
pythonwin running

This shouldn't have any overhead. Writing a predicate function is
left as an exercise to the reader.
Jul 18 '05 #6
how can my script know it its running from inside PythonWin?


I addressed this a few months ago:

import sys
if len(sys.modules) > 200: # running under PythonWin

This is because PythonWin loads a lot of modules beyond what native Python
does. (IDLE also loads some, but a lot less that PyrthonWin).

Bob Gailer
bg*****@alum.rpi.edu
303 442 2625
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.500 / Virus Database: 298 - Release Date: 7/10/2003

Jul 18 '05 #7
Try this:
import win32ui
win32ui.GetCommandLine()
'"C:\\Python23\\Pythonwin.exe" '
hth
Roger
"Martin Bless" <mb@muenster.de> wrote in message
news:3f*************@news.muenster.de... IMHO PythonWin is great help in developing.

How can I do something like:

if detect("running on PythonWin"):
pass
# fake arguments ...
else:
"proceed normal"

?

Martin

Jul 18 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: stephan | last post by:
Hi, I have python 2.2.3 + pythonwin 156 on win2k. The problem is that german chars like äöüÄÖÜß are not handled correctly. Just create a test.py file with the content äöüÄÖÜß and edit it with...
3
by: Alberto Mantovani | last post by:
hi, how is it possible to run a python script in the pythonwin environment from dos command line? If I use the command "/run scriptname.py" and the pythonwin is already opened I get error, so...
14
by: Jive | last post by:
I've un-installed Python 2.4, re-installed Python 2.3 and PythonWin for 2.3, but it's still broke. When I start PythonWin, sometimes it looks like it is going to be okay. But as soon as I open...
4
by: Chris P. | last post by:
I've been having a problem with PythonWin that seemed to start completely spontaneously and I don't even know where to START to find the answer. The only thing I can think of that marks the point...
2
by: siggy2 | last post by:
Hi All, (sorry for my bad english) I wrote a __tiny__ and __stupid__ recursive script directly into pythonwin interactive window with a time.sleep(1) and a print before each recursion... I...
2
by: accolades | last post by:
Does anyone else have a problem with Pythonwin crashing after running a python script with graphics libraries? Whenever I use Pythonwin to run a PyGame or PyOgre script, Pythonwin crashes when the...
17
by: Dave Benjamin | last post by:
Hey folks, Why is PythonWin (win32all) still a separate download from a third party? Is it legal, technical, or what? I think it's about time it be part of the standard distribution. There...
3
by: archaegeo | last post by:
I am getting started in Python, and I have looked on both the stackless page and python.org and cannot find the answer to what I think is a simple problem. If I start the python command line or...
4
by: sterling | last post by:
I'm curious as to why the difference between IDLE and pythonWin when using win32com. opening an excel file, i've attempted to grab the chart information out of the file. commands like co =...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.